I keep getting the wrong result when i run the program i get 44.5596 but what i am supposed to get is 0.446 my mistake is probably small but i just don't get it.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
const int AT_BAT = 579;
const int HITS = 258;
int main()
{
float batAvg;
batAvg = HITS * 100.00 / AT_BAT;
cout << "The batting average is " << batAvg << endl;
system("pause");
return 0;
}
The (float) is a typecast. This is making sure at least one of the variables is a float so that it will return a float into batAvg. You can also do it the preferred C++ way which is static_cast<float>(HITS) / AT_BAT; .