I am trying to create a program that prompts the user to input a fraction such as 5/3 and then simplify the fraction so 5/3 would be 1 2/3. The issue is that the input is displayed as a fraction. Numerator/denominator. When I prompt for the denominator I get 0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
cout << "Please enter a fraction (numerator / denominator)" << endl;
cin >> numerator;
cin >> denominator;
cout << denominator << endl;
Please enter a fraction (numerator / denominator)
5 / 6
Any ideas??? Obviously the program isn't complete but I want to fix this problem first.
Note that you don't have to have spaces in between the number and the character (in this case the slash). Also, I wouldn't recommend relying on "cin >> blah blah blah;" too often. You should look at other methods of input, like getline(...);. It's less buggy, but "cin >> ..." is fine for training purposes.