0

This my first C++ programming class and I'm not that good with C++, so please help me out. This is due in 4 hours. This is what i got and i got a lot of errors. Thank you and once again please help me.


1.Repeatedly reads a student score (for exam) and adds it to a running sum. Count the number of scores entered. (assume score are between 0-100) Stop when the user enters a negative number. Display the sum and count of the score onscreen.

#include <iostream>
using namespace std;
int main(){
int score, sum, count;
while(score<= 100 && score >=0){
cout << “enter a score:” ;
cin >> score;
count = 0;
count++;
sum= 0+score;
}
cout << sum;
cout<<count;
return 0;
}

2.
Defines a function "average" that, when passed the su of the scores and the count of the scores, computes and returns the average score. In main, call this function just after the above loop in problem 1, and display onscreen the average score that the function returns.

#include <iostream>
using namespace std;
average(X,Y);
int main(){
int score, sum, count;
while(score<= 100 && score >=0){
cout << “enter a score:” ;
cin >> score;
count = 0;
count++;
sum= 0+score;
}
cout << sum;
cout<<count;
return 0;
}
average(SUM, COUNT){
return sum/count;
}
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by ~s.o.s~
0

You need to tell us exactly the errors you are getting and where.

As far as your first program is considered, you need to initialize the variables at the top of your program, since without that while(score<= 100 && score >=0) becomes meaningless. sum= 0+score What is this statement supposed to do ? It just adds zero to score and assigns it to LHS ie sum. Maybe you wanted sum = sum + score or sum += score In your second program :

// wrong way to declare a function
// you need to specify the return type and the 
// number and type of function parameters...

// int average( int, int ) ; would be more like it
average(X,Y); 

// more code

// ditto here, you need to specify the return type along
// with the type of input parameters along with their names

// int average( int sum, int count ) { /* code * / } would be more like it
average(SUM, COUNT){
return sum/count;
}

Read the comments in the code I posted above for tips.

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.