HELP please??

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*********************************************************
* 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>
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.