Array + dividing sum of arrays

Hi guys, I need help with a program I have been scratching my head over in which I can't seem to realize the problem. I have a program where a user enters 10 scores, and C++ outputs mean, min, and max. I got the min and max part right but the average just will not output the right value. It is always 0 or the max value...any help is appreciated.
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
37
38
39
40
41
42
43
44
        //Declare variables
	float score[10],avg,min,max,sum=0;
	int count=1,i;
	
	//Run loop
	for(i=count;i<=10;i+=1){
		cout<<"\nEnter score "<<i<<": ";
		cin>>score[i];
	}
	
	//Compute data
	for(i=count;i<=10;i+=1){
		sum = sum + score[i];
	}
	
	//Calculate average
	sum = (sum/10.0);
	
	//Calculate max and display
	max=score[1];
	for(i=count;i<=10;i+=1){
		if(max<=score[i]){
			max = score[i];
		}
	}
		
	//Calculate min and display
	min=score[1];
	for(i=count;i<=10;i+=1){
		if(min>=score[i]){
			min = score[i];
		}
	}
	
	//Display inputs and calculations
	cout<<"Using values: ";
	for(i=count;i<=10;i+=1){
	cout<<score[i]<<", ";
	}
	cout<<"\nThe average is: "<<avg<<"\nThe \
minimum is: "<<min<<"\nThe maximum is: "<<max;

	return(0);
}
Last edited on
So no one wants to help a stranded student who has a very-diligent program due tomorrow?
Nice.

I love programming'ers!
Last edited on
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
37
38
39
40
41
42
43
44
45
#include <iostream>

int main() {

     // program where a user enters 10 scores, and outputs mean, min, and max.

     const int NSCORES = 10 ; // number of scores

     // accept the first score
     double score ;
     std::cout << "enter score: " ;
     std::cin >> score ;

     // initially, the min and max is he first score
     double min = score ;
     double max = score ;

     double sum = score ; // the sum so far is just the first score

     // for the remaining NSCORES-1 scores
     for( int i = 0 ; i < (NSCORES-1) ; ++i )
     {
         // read n the score
         std::cout << "enter score: " ;
         std::cin >> score ;

         sum += score ; // add this score to the sum

         // if this score is smaller than the minimum so far,
         if( score < min ) min = score ; // then this becomes the minimum

         // if this score is larger than the maximum so far,
         if( score > max ) max = score ; // then this becomes the maximum
     }

     // compute the average score
     const double average = sum / NSCORES ;

     // print out the results
     std::cout << "# scores: " << NSCORES << '\n'
               << "     sum: " << sum << '\n'
               << " average: " << average << '\n'
               << " minimum: " << min << '\n'
               << " maximum: " << max << '\n' ;
}
Thank you for the reply @JLBorges. But boy did my professor teach C++ in a different way! She taught us in the most basic form and I never really understood the std:: part of it. This is mostly due to me being in an engineering course, not comp sci. (They require engineers to learn a little C++...)
Appreciate the effort though,
Last edited on
Topic archived. No new replies allowed.