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
/*********************************************************
* 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 <iostream>
usingnamespace 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;
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 .