How do I convert this to a decimal without using float/double?

closed account (3CGE8vqX)
In the last line, I need to make the previous line's fraction into a decimal but can't use float or double, but I'm not sure how.



#include <conio.h>
#include <iostream.h>



int main ()
{

// "housekeeping"
int nume, denom, numden;

// input section
cout << "Input the numerator of the fraction" << endl;
cin >> nume;
cout << "Input the denominator of the fraction" << endl;
cin >> denom;

// output section
cout << "The fraction is " << nume << "/" << denom << endl;
cout << "The whole number is " << nume/denom << endl;
cout << nume << "/" << denom << " is equal to " << nume/denom << " " << nume%denom << "/" << denom << endl;
cout << nume << "/" << denom << " is equal to " << nume/denom << endl;

return 0;

}
You could cast to a float/double.

1
2
3
num / static_cast<double>(denom)
//or
num / (double)denom


There are other ways too but these would probably be your best bet.
Topic archived. No new replies allowed.