Decimal to Fraction Calculator

Hey guys,
So I'm trying to write program that converts decimals to fractions but it is not working. I have the code pasted below. I'm open to any ideas. Thanks!

int main()
{
char n = 0;//for decimal point
char x = 0;//for tenths place
char y = 0;//for hundredths place
std::cout << "Please enter the decimal to the hundredths place here: ";
std::cin >> n;
std::cin >> x;
std::cin >> y;
if (x == 0)
std::cout << 0 << y << "/100";
if (y == 0)
std::cout << x << "/10";

if (y == 1 || y == 2 || y == 3 || y == 4 || y == 5 || y == 6 || y == 7 || y == 9)
std::cout << x << y << "/100";

}
closed account (48bpfSEw)
"/100" is a text.

if you want to divide numbers use : y / 100

your if clause can be shortend : if (y >= 1 && y <=9)
Thanks!
Topic archived. No new replies allowed.