here is my program #include <iostream> using namespace std; int main() { // User
ID: 3536772 • Letter: H
Question
here is my program
#include <iostream>
using namespace std;
int main()
{
// User Instructions
cout << "****************User Instructions***************" << endl;
cout << " This program will read and store the numerators" << endl;
cout << " and denominators of two fractions as integer values." << endl;
cout << "************************************************" << endl;
cout << endl;
//Variables
int Fnum ,Fden, Snum, Sden;
int FracAns=0;
float PercAns =0;
//Statements
cout<<"Please enter a fraction!"<<endl;
cin>>Fnum;
cin>>Fden;
cout<<"Please enter a second fraction!"<<endl;
cin>>Snum;
cin>>Fden;
if (Fden || Sden==0)
{
cout<<"Sorry you cannot divide by 0!"<<endl;
}
//Formulas
FracAns = Fnum*Snum / Fden*Sden ;
PercAns = FracAns / 100;
//Statements
cout<< "The result of the product is... "<<endl;
cout<<FracAns<<endl;
cout<< " and the percentage is "<<PercAns<<endl;
return 0 ;
}
//end of program
//In the design section, take the tasks you identified in the analysis section and write them in the form of a pseudocode algorithm. Refine your steps until you cannot refine them further.
//
//Desk-check your algorithm and list the inputs you used and the results you obtained.//
//Test your program with your desk-check data. Describe the results here. Try at least one other set of test data and record the results.//
Explanation / Answer
line 27: Fden should be Sden
if Fden or Sden==0; either exit(line 29-32) or use:
while(1){
cin>>x;
if(x!=0)
break;
else
{cout<<"x cannot be zero"
continue;}
}
line 36: PercAns = FracAns*100;
(atleast thats what i assumed, since thats what percentage means)
*DESIGN
integers Fnum ,Fden, Snum, Sden, FracAns
decimals PercAns
input value of Fnum
while Fden is not 0
input value of Fden
input value of Snum
while Sden is not 0
input value of Sden
FracAns set to (Fnum*Snum/Fden*Sden) ;
PercAns set to (FracAns*100);
print(FracAns)
print(PercAns)
*TEST PLAN
desk_check:
Fnum Fden Snum Sden FracAns PercAns(%)
0 1 0 2 0 0
0 1 17 2 0 0
1 1 1 1 1 100
1 2 1 5 0.1 10
2 8 7 35 0.05 5
0 1 0 2 0 0
3 7 11 5 0.942857 94.2857
13 3 2 3 2.888888 288.8888
*TESTING
Fnum Fden Snum Sden FracAns PercAns(%)
0 1 0 2 0 0
0 1 17 2 0 0
1 1 1 1 1 100
1 2 1 5 0 0
2 8 7 35 0 0
0 1 0 2 0 0
3 7 11 5 0 0
13 3 2 3 2 200
FracAns is an integer.
If its value is less than 1, in the program the value will be stored as 0.
If its value is more than 1, in the program the digits after the decimal point will not be stored.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.