Cannot compute equation, always gives zero
- by user1738391
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();
}