简体   繁体   中英

conversion from double to float in c++

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;

    }

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.

Looks fine to me too. You do know that you have to add the numbers one by one on their own lines, eg 5 , 3 , 4 ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM