1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
to make it easy, lets do this:
int* marks[6]{nullptr,mark1,mark2,mark3,mark4,mark5};
and extend lowmark:
int lowmarks[6];
and its a lot like what you have...
for(i = 1; i < 6; i++)//1,2,3,4,5
lowmarks[i] = marks[i][0];
and the other for loop becomes
for(i = 1; i < 40; i++)
{
for(j =1; j<6; j++)
if(lowmarks[j] < marks[j][i])
lowmarks[j] = marks[j][i];
}
| |
which brings up a couple of points...
I used 6 so that marks[1] is marks1 which is easy to remember and follow. its confusing if marks[0] is marks1.
which implies that marks1 should be marks0 ... number things from zero in c++!
and the other thing is... do not make a bunch of the same thing with slight name variations, make an array of them (later, a vector).
I backfed your marks into an array to make it like that, but ideally, marks would have been a 2d array to begin with. If you had done that, your cin loop would not repeat the same code 5 times, but would be like my above loop, using the 'array of mark arrays' to reduce that code to a couple of lines.
finally, your code has a bug. you let the user stop typing with a 999 but you don't retain this information. That means that the processing loops look at invalid data. you should keep a count of how many they entered and only look for the lowest in the valid input range... This is probably why it does not work, I am willing to bet you stopped before typing 40 values in :)
on that note, you can make a text file of 40 values and feed it to the program using the < operator on the command line when you run the program, or IDE will let you feed it from there, if you want to test 40 numbers, or you can put in random values in a range. Or the easy way out, change 40 to 5 and test with the reduced size until it works then upgrade the size again. which leads to... make the numbers a constant so you only have to change the 40 in one place to do that idea (best practice, always name constants, do not just have 37 and 98 and whatnot embedded in code here and there with no clue what those numbers refer to). If the constant is math or something, a comment is ok instead, eg x = sqrt(2.0)*y; //sqrt 2 is because some formula for what I am doing here type comment.