Cannot compute equation, always gives zero

Posted by user1738391 on Stack Overflow See other posts from Stack Overflow or by user1738391
Published on 2012-10-14T09:28:48Z Indexed on 2012/10/14 9:37 UTC
Read the original article Hit count: 177

Filed under:
|

Did i miss something? The variable percentage_ always equals 0. I've checked nTimes and winnings, they give the correct values as what is being input. Even when I test out a simple equation like, percentage_=1+1, percentage_ will give 0. Can someone help?

    #pragma once
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <iomanip>

    using namespace std;


    class GuessMachine
    {
    private:
        int nTimes;
        int winnings;
        string nM[6];

    public:
        GuessMachine();
        void displayPrizes();
        void displayMenu();
        int getInput();
        void checkNumber();
        void checkPrize();
    };



    void GuessMachine::checkPrize()
    {
        MagicNumber mn;
        int prize_=mn.generateNumber();
        float percentage_;

        percentage_ = float (winnings/nTimes*100); //<--On this line percentage is always 0 no matter what winnings and nTimes are
        cout<<"Percentage is "<<percentage_<<endl; 

        if(percentage_ >= 50)
        {
            cout<<"You have scored "<<percentage_<<"% and won "<<nM[prize_];
        }
        else
        {
            cout<<"You have scored "<<percentage_<<"%. You lose!!";
        }

        cin.ignore();
        cin.ignore();
    }

© Stack Overflow or respective owner

Related posts about c++

Related posts about equation