empty out put.

#include <iostream>
using namespace std;
int main()
{
int i,scores[5],max;
cout <<"Enter 5 scores: " << " ";
cin >> scores[0];
max = scores[0];
for (i=0; i<5; i++)
{
cin >> scores[i];
if (scores[i] > max)
max = scores[i];
}
cout << "The highest score is: " << max ;
system("pause");
return 0;
}
Looks like there are a lot of students working on the same assignment.
The code runs something, after putting the five values. it outputs nothing!

#include <iostream>
using namespace std;
int main()
{
int i,scores[5],max;
cout <<"Enter 5 scores: " << " ";
cin >> scores[0];
max = scores[0];
for (i=0; i<5; i++)
{
cin >> scores[i];
if (scores[i] > max)
max = scores[i];
}
cout << "The highest score is: " << max ;
system("pause");
return 0;
}
It probably isnt working because you are missing several braces. You need an opening brace on the line after your if statement, and then you will need another closing brace to finish your for loop. It should look like this. Also, instead of using system("pause"), you should be able to replace that code with cin.get();cin.get(); which will not show the message press any key to continue. Another thing, I don't know what your professor wants but you do not really need your main function to be type int. your not returning anything so you should be able to make it type void and then you can remove the return 0 line of code

#include <iostream>
using namespace std;
void main()
{
int i,scores[5],max;
cout <<"Enter 5 scores: " << " ";
cin >> scores[0];
max = scores[0];
for (i=0; i<5; i++)
{
cin >> scores[i];
if (scores[i] > max)
{
max = scores[i];
}
}
cout << "The highest score is: " << max ;
cin.get();cin.get();
}
closed account (1yR4jE8b)
Do not ever make main() function of type void, it is non standard. Certain compilers flat out reject it. The main function should always return an int, because it needs to give the operating system an exit status.
Also, his if statement doesn't absolutely NEED braces because the the branching statement is only one line.

Also, the algorithm with the algorithm used you would actually need to input 6 values before seeing any output. Because first you input a value into scores[0] then you loop from 0 to 4, which is 0, 1, 2, 3, 4. You are overwriting your original score value and you are most likely just not inputing your final value and that's why you're not getting output.
Last edited on
Topic archived. No new replies allowed.