This is my first post so...

I had to write a program that got the product of two fractions. I think I did that part correctly but I it also said that the output needed the fraction and a decimal form of the the fraction, and I am totally lost as to how to even come up with it. This is what I have so far I'm just learning so can you keep it simple or explain in detail. I'm not looking for anybody to answer the question I just want to know what do I do to get the decimal to show up

Thanks in advance for the help
 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 /********************************************************* * file name: 2.6_HW.cpp * programmer name: Robert Duckett * date created: 9/5/12 * date of last revision: * details of the revision: none * short description: Program prints product of two fractions **********************************************************/ #include using namespace std; int main() { //Declare int a; int b; int d; int t; float ansnum; float ansdenom; //Initialize //Input cout << "Enter the numerator for the first fraction" << endl; cin >> a; cout << "Enter the denominator for the first fraction" << endl; cin >> b; cout << "\n" << endl; cout << "Enter the numerator for the second fraction" << endl; cin >> d; cout << "Enter the denominator for the second fraction "<< endl; cin >> t; cout << "\n" << endl; //Calculate ansnum = a*d; ansdenom = b*t; //Output cout << ansnum << "/" << ansdenom << endl; system("PAUSE"); return 0;
Last edited on
Hi there,

In order to get the decimal, you'll have to divide the ansnum by the ansdenom variables.
For instance, fraction 1/2 in decimal is the outcome of 1 divided by 2 = 0.5 .

Hope that helps.

All the best,
NwN
Thank you sorry for the late reply but it worked perfectly
Topic archived. No new replies allowed.