0

This program is correct, it repeatedly asks the user to enter a score till you enter a negative or a number over 100. Than it adds all the scores and counts how many scores entered.

Now the problem is I have to write a function called "average" that will will return the average (total sum/count). I am not sure how to do that.
Can someone Halp me Please. Average must be a function.

#include<iostream>
usingnamespace std;
 
int main(){
int score, sum, count;
cout << "enter a score:" ;
cin >> score;
count = 1;
sum = score;
while(score >= 0 && score <= 100){
cout << "enter a score:" ;
cin >> score;
sum = sum + score;
count++;
}
cout << sum << endl;
cout << count << endl;
 
return 0;
}
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by ~s.o.s~
0

You can write the function something along the lines of:

double average( int my_sum, int my_count )
{
   // write your code here
}

int main( void )
{
     // all other declarations
     double avg = 0.0 ;

     // write the code which accepts scores
  
    avg = average( sum, count ) ;
}

Fill in the spaces and you should get the program up and running...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.