Arrays- this gives right answer but after the "Enter score for" part weird numbers come after it and ill show u in the reply

#include <iostream>
#include <cstdlib>
using namespace std;

int main ()
{
int score[5];
int total=0;
for(int a=0; a<=4; a++)
{
cout<<" Enter score for" << score[a]<< ":";
cin>> score[a];
total += score[a];
}
double x= total/5.0;
cout<<x<<endl;

return 0;
}
Enter score for-269553408:1
Enter score for52:2
Enter score for4196999:3
Enter score for0:4
Enter score for-269590272:5
3
closed account (3hM2Nwbp)
Maybe this is what you want

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main ()
{
    int score[5];
    int total=0;
    for(int a=0; a<=4; a++)
    {
        cout<<" Enter score for" << a<< ":"; // <-- Changed this line
        // score[a] was printing garbage because it was never initialized.
        cin>> score[a];
        total += score[a];
    }
    double x= total/5.0;
    cout<<x<<endl;
    return 0;
}


Enter score for 0 : 1
Enter score for 1 : 2
Enter score for 2 : 3
Enter score for 3 : 4
Enter score for 4 : 5
3
Last edited on
ok that works, thanks and another question how would i get the average of the inputs that are greater or equal to x
Topic archived. No new replies allowed.