Cant get input to be used in calculation

i am new c++ learner and i am writing this program thats supposed to take input from the use and calculate the average but i cant seem to get the input to be used only the declared value is used. what am i doing wrong?
also, how to i stop the console from closing out after the program excutes, i have beeing using cin>>average in the last line but i know thats not how its done..

Here is the code:


// Game Score
// Program gets three scores from the user and displays the average.

#include <iostream>


using namespace std;



int main()
{
int score1, score2, score3, averagescore;

score1 = 0;
score2 = 0;
score3 = 0;
averagescore = (score1 + score2 + score3) / 3;



cout <<"\nEnter Score for Game 1: "; // gets the first game score
cin >> score1; // outputs value entered by user
cout << "score1: " << score1 << endl;


cout << "\nEnter Score for Game 2: "; // gets the second game score
cin >> score2; // outputs value entered by user
cout << "score2: " << score2 << endl;


cout << "\nEnter Score for Game 3: "; // gets the third game score
cin >> score3; // outputs value entered by user
cout << "score3: " << score3 << endl;


cout << "\n\nThe Average Game Score is: " << averagescore << endl;

cin>>averagescore;



return 0;
}



I like that you use comments in your code.


averagescore = (score1 + score2 + score3) / 3;

should go after you get the users input


Also Remove cin>>averagescore;

It should look like this:
1
2
3
cout << "score3: " << score3 << endl;
averagescore = (score1 + score2 + score3) / 3; 
cout << "\n\nThe Average Game Score is: " << averagescore << endl;
Last edited on
Thanks a lot SamuelAdams, now it works, and i have been tearing my hair off...!
I am loving C++ and hope to learn a lot more from the forum....

also thanks for sharing about the code tags, will surely use them from now on.
Topic archived. No new replies allowed.