Reputation: 53
I am new to programming. Here is part of my assignment, which requires using pass-by-reference. After I compile it and type in the values for win, draw and loss respectively,it returns me nothing. I don't know whether it is due to the problem in calling the function or the floating point.
void Cfunction(int win, int draw, int loss, float& point)
{
point = win * 2.5f + draw * 1 + loss * 0;
}
int main(void)
{
int win, draw, loss;
float point;
cout << "Please input the game record in the following order: win draw loss " << endl;
cin >> win >> draw >> loss;
Cfunction(win, draw, loss, point);
cout << "The total score for the team is " << point << endl;
}
Upvotes: 0
Views: 940
Reputation: 11
Looks fine to me too. You do know that you have to add the numbers one by one on their own lines, e.g. 5 , 3 , 4 ?
Upvotes: 0
Reputation: 41509
Look good to me.
You could verify that your cin >> ...
has finished by adding a cout << "calculatin total score...." << std::endl;
.
(Note: std::cin >> wins
has the wins
variable passed by reference, too :))
Indeed, as @David Hefferman suggested, learn to use the debugger. Will save you a huge amount of time in the (very near) future.
Upvotes: 1