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%
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:
#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