im new in function, can u find my error?

Why is my input ask the user to enter the score twice?

#include<iostream>
using namespace std;
void getScore(int&);
void printGrade(int);
int main()

{

int score;
int course;
getScore(score);
printGrade(course);
return 0;
}

void getScore(int& score){

cout<<"Please enter your score: ";
cin>>score;
cout<<"Your course score is: "<<score<<endl;


}

void printGrade(int course){

getScore(course); //im not really sure about this, correct me if im wrong
if(course<0 || course>100)
cout<<"Wrong input! Try again!"<<endl;
else if(course>90)
cout<<"Course grade= A"<<endl;
else if(course>70)
cout<<"Course grade= B"<<endl;
else if(course>=50)
cout<<"Course grade= C"<<endl;
else
cout<<"Course grade= D"<<endl;


}
Because you call getScore() twice. You call it once from main(), and once from printGrade().

When posting code, please use code tags to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/
oh crap! my fault. Im new to this forum, thats why. Btw, thanks. I get it now, simple mistake. how can i overlooked it.
You're welcome - glad it worked out :)
Topic archived. No new replies allowed.