Results 1 to 3 of 3
Threaded View
-
31st Jan 2012, 02:33 AM #1OPMemberWebsite's:
scenator.comC++ help.
Been having issues with this all night, here's the question.
Q: Write a program that reads the numerators and denominators of two fractions. Your program should print the numerator and denominator of the fraction that represents the product of the two fractions. Also, print out the percent equivalent of the resulting product.
So here's my code, I'm pretty sure my math is right. It displays the product of the two fractions properly, but when it comes to the percentage it always gives me 0.00%
PHP Code:#include <iostream>
#include<iomanip>
using namespace std;
void main()//start main
{
int n1,n2,d1,d2;
int n,d;
float p;
cout<<"Enter Numerator #1: ";
cin>>n1; //First numerator
cout<<"Enter Denominator #1: ";
cin>>d1;//First denominator
cout<<"Enter Numerator #1: ";
cin>>n2; //Second numerator
cout<<"Enter Denominator #1: ";
cin>>d2;//Second denominator
n=n1*n2;//Numerator product
d=d1*d2;//Denominator product
p=n / d * 100; //Converts to percent
cout<<"Fraction Answer: "<<n;
cout<<"/"<<d <<endl;
cout<<"Percentage Answer: "<<fixed << setprecision(2)<<p;
cout<<"%" <<endl;
system("pause");
}//end main
jSx@ECD Reviewed by jSx@ECD on . C++ help. Been having issues with this all night, here's the question. Q: Write a program that reads the numerators and denominators of two fractions. Your program should print the numerator and denominator of the fraction that represents the product of the two fractions. Also, print out the percent equivalent of the resulting product. So here's my code, I'm pretty sure my math is right. It displays the product of the two fractions properly, but when it comes to the percentage it always gives me Rating: 5
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
themaCreator - create posts from...
Version 3.45 released. Open older version (or...