Click to See Complete Forum and Search --> : programing help
monolith1986
December 6th, 2006, 03:08 PM
I am taking a online c++ programing class. Since its online i have no real instructer to help me understand the course. Our finals are due friday and one of the programing problems on it has got me stuck. I would really appreciate it if some one on here would be willing to help me by either giving me pointers in the right direction or making the program for me its not that its hard i just dont have the materials needed to help me figure it out.
heres the problem
Create a program which will generate a 5x5 matrix of random generated numbers using a muti dimensional array. Your values should range from 1 to 100. You will need to display the array to the screen, then the program will display the max value for each row and the max value for the array.
im shure it wouldnt take some one experinced to make something like this but i cant barly get a array with random numbers to work.
cvogt61457
December 6th, 2006, 04:07 PM
Post the code that you have.
State what the problems are with your code. Be as specific as possible.
(Use the code tags when you post the code to make it easier to read)
dcjr84
December 6th, 2006, 04:43 PM
While it is true that most of us here could write such a program easily, that is not the point.
You aren't going to learn anything by us doing that.
Surely, if you have gone over an entire semester of basic C++, you have covered multi-dimensional arrays, random numbers, loops, if-else statements, and basic functions. This is all you need to do this.
Try to do it yourself, and come back later and ask questions if you get stuck.
I am willing to bet you could at least write enough code to be able to declare a 5 x 5 array, even if you don't know what to do with it.
Don't get overwhelmed. Take a deep breath, and start with this...
int main()
{
return 0;
}
And build off of that :D
Also, on a side note, learning C++ in an online course is probably not a good idea. IMO, there is no substitute for having an actual human being teach you something, where you can ask questions and learn things in real time, instead of having to learn it yourself out of a book. The book is a good supplement to learn with, but you need someone readily available who you can ask questions.
monolith1986
December 6th, 2006, 05:06 PM
alright its not that i dont really know how to do any of this im just really pressed for time. I take online classes cause i work full time ive got more of a sob story but it dont matter. but heres what i got it dosnt work.
#include <cstdlib>
#include <ctime>
#include <iostream>
static const int conROWS = 5;
static const int conCOLS = conROWS;
int main(int argc, char* argv[])
{
int matrix[conROWS][conCOLS];
int maxvalue;
int r,c;
srand(clock() + time()); //seed the random number generator
//fill matrix with random values in range 1..100
for(r=0; r<conROWS; r++)
{
for(c=0; c<conCOLS; c++)
{
matrix[r] = (rand() % 100) + 1;
std::cout << matrix[r] << " ";
};
std::cout << std::endl;
};
//work out max row element
for(r=0; r<conROWS; r++)
{
maxvalue= 0;
for(c=0; c<conCOLS; c++)
{
if(matrix[r] > maxvalue)
maxvalue = matrix[r];
};
std::cout << "Max value in row " << r << " is " << maxvalue;
};
//todo workout max value overall and display it
return 0;
};
I hope this proves to you i know kinda what im doing and i would appreciate it of some one more experenced then me would get this up and running for me.
MrViggy
December 6th, 2006, 05:18 PM
Well, take the first element in the row, and compare it to all the others, keeping the max value. At the end, you should have the max element in that row.
Now, take the max element in the first row, and compare it to the max value from all the other rows, keeping the max. At the end, you have the max value in the array.
You just need to work out how to save the individual rows' max value (hint, single dimentional array might do it).
Viggy
dcjr84
December 6th, 2006, 05:27 PM
Ok well, the majority of this looks fine. Some small errors.
1) Don't put semicolons after your closing braces (except when declaring a class). Semicolons belong at the end of statements.
...
//fill matrix with random values in range 1..100
for(r=0; r<conROWS; r++)
{
for(c=0; c<conCOLS; c++)
{
matrix[r] = (rand() % 100) + 1;
std::cout << matrix[r] << " ";
};
std::cout << std::endl;
};
...
2) Seed the random number generator with the system time
...
srand( time( NULL ) ); //seed the random number generator
...
3) In the double nested loop where you assign random numbers, you only specify one dimension...
...
matrix[r] = (rand() % 100) + 1;
std::cout << matrix[r] << " ";
You need to specify both dimensions, like this
...
matrix[r][c] = (rand() % 100) + 1;
std::cout << matrix[r][c] << " ";
...
Also, you code to return the maximum element in a row needs work. Take a look at it.
dcjr84
December 6th, 2006, 05:56 PM
I take online classes cause i work full time ive got more of a sob story but it dont matter.
Not that I want to start an argument, but I work 40 hours a week and take 16-18 credit hours a semester at a 4 year University (and have never taken an online course), and I always manage to get my work done on time. Though I will admit, I have been rather stressed at certain times, but I am going to graduate in May nonetheless.
monolith1986
December 6th, 2006, 06:31 PM
yea well try doing that ontop of taking care of your two dying parents being in and out of hospitals at all hours of the night .. you know **** it sorry i asked yall for help
dcjr84
December 6th, 2006, 06:36 PM
yea well try doing that ontop of taking care of your two dying parents being in and out of hospitals at all hours of the night .. you know **** it sorry i asked yall for help
I have already done that years ago when my parents died, so don't even try to pull that card out and make me look like an idiot.
No need to get so upset. We were trying to help you, but not if you are going to get an attitude about it and use profanity.
monolith1986
December 6th, 2006, 07:15 PM
well then you know exactly how i feel (pulling no cards) and no you wernt helping you were being a smart *** telling me oh here start with int main and return 0 and work your way from there. then to say hey i can do this so you shouldnt get help maybe you should of just kept your opinion to yourself.
dcjr84
December 6th, 2006, 07:30 PM
well then you know exactly how i feel (pulling no cards) and no you wernt helping you were being a smart *** telling me oh here start with int main and return 0 and work your way from there. then to say hey i can do this so you shouldnt get help maybe you should of just kept your opinion to yourself.
Did you even read my last post where I helped you out by making all those corrections? Apparently not.
then to say hey i can do this so you shouldnt get help
Perhaps English is not your native language, so let me clarify.
To quote myself...
While it is true that most of us here could write such a program easily, that is not the point.
You aren't going to learn anything by us doing that.
Surely, if you have gone over an entire semester of basic C++, you have covered multi-dimensional arrays, random numbers, loops, if-else statements, and basic functions. This is all you need to do this.
Try to do it yourself, and come back later and ask questions if you get stuck.
Where in there does it say "then to say hey i can do this so you shouldnt get help"? Nowhere. I said you won't learn anything by us doing your homework for you, and you should try doing it yourself, and then come back and ask for help.
You did not post any code at this point. You came on here saying "alright its not that i dont really know how to do any of this im just really pressed for time." , which is rather arrogant. People on here have jobs, and other things to do. We do not want, nor have the time, to do other people's homework assignments here. If you don't like that, go elsewhere.
If you want help, like myself and Mr. Viggy were offering, I suggest you calm down and take a deep breath. If not, then bye bye.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.