hey i need help resetting my average to zero

hey I'm really new to c++ and need help with a few errors I'm having in my program. the first problem is finding the low score in my program it only prints 0 the second issue I'm having is the average i only need it to find the the average per id number.

[code]
int main() {
int athleteid, judge=0, highscore = 0,lowscore=0, winnerid;
double score=0,sum=0,athletehighscore=0;
double avgscore = 0.0;

cout<< " enter athlele id ";
cin>> athleteid;
cout<< " enter amount of judges ";
cin>> judge;
while ( athleteid >= 0 ){
for (int i=1; i <=judge; i++){
cout<< " enter score ";
cin>> score;

sum += score;


if (score>highscore)
highscore=score;


if (score<lowscore){
lowscore=score;
}
}

avgscore = sum/judge;
cout<<" high score " << highscore<< endl;
cout<<" low score " << lowscore << endl;
cout<<" average score " << avgscore << endl;
cout<<" enter athlele id ";
cin>> athleteid;



}
Set your lowscore variable to 100 instead of 0 or so...because your if statement you currently have set will only fire if your score is less than 0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int main() {
int athleteid, judge=0, highscore = 0,lowscore=0, winnerid;
double score=0,sum=0,athletehighscore=0;
double avgscore = 0.0;

cout<< " enter athlele id ";
cin>> athleteid;
cout<< " enter amount of judges ";
cin>> judge;
while ( athleteid >= 0 ){
for (int i=1; i <=judge; i++){
cout<< " enter score ";
cin>> score;

sum += score;


if (score>highscore)
highscore=score;


if (score<lowscore){
lowscore=score;
}
}

avgscore = sum/judge;
cout<<" high score " << highscore<< endl;
cout<<" low score " << lowscore << endl;
cout<<" average score " << avgscore << endl;
cout<<" enter athlele id ";
cin>> athleteid;



}
Last edited on
Topic archived. No new replies allowed.