This is what I have so far: #include<iostream> using namespace std; double added
ID: 3775400 • Letter: T
Question
This is what I have so far:
#include<iostream>
using namespace std;
double added(double Num1, double Num2, double& Sum)
double multiplied(double Num1, double Num2, double& product )
double divided(double Num1, double Num2, double& quotient)
double subtracted(double Num1, double Num2, double& difference)
int main()
{
double Num1, Num2, answer;
int code;
cout<<"Please enter one number: ";
cin>>Num1;
cout<<"Please enter a second number: ";
cin>>Num2;
while(Num1!=0 || Num2!=0)
{
cout<<endl;
cout<<"1. + ";
cout<<"2. * ";
cout<<"3. / ";
cout<<"4. - "<<endl;
cout<<"Please indicate a code: ";
cin>>code;
cout<<endl;
switch(code)
{
case 1:
answer=Num1+Num2;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<<"."
<<" Your sum is "<<answer<< "."<<endl;
break;
case 2:
answer=Num1*Num2;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<< "."<<
cout<<"Your product i: "<<answer<< "."<<endl;
break;
case 3:
answer=Num1/Num2;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<< "."
<<cout<<"Your quotient is "<<answer<< "."<<endl;
break;
case 4:
answer=Num2-Num1;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<< "."
<<cout<<"Your difference is "<<answer<< "."<<endl;
break;
default: cout<<"You entered 0 for both numbers.";
}
}
return 0;
}
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
double Num1, Num2, answer;
int code;
cout<<"Please enter one number: ";
cin>>Num1;
cout<<"Please enter a second number: ";
cin>>Num2;
while(Num1!=0 || Num2!=0)
{
cout<<endl;
cout<<"1. + ";
cout<<"2. * ";
cout<<"3. / ";
cout<<"4. - "<<endl;
cout<<"Please indicate a code: ";
cin>>code;
cout<<endl;
switch(code)
{
case 1:
answer=Num1+Num2;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<<"."
<<" Your sum is "<<answer<< "."<<endl;
break;
case 2:
answer=Num1*Num2;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<< "."<<
cout<<"Your product i: "<<answer<< "."<<endl;
break;
case 3:
answer=Num1/Num2;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<< "."
<<cout<<"Your quotient is "<<answer<< "."<<endl;
break;
case 4:
answer=Num2-Num1;
cout<<"The first number is "<<Num1
<<" and the second number is "<< Num2<< "."
<<cout<<"Your difference is "<<answer<< "."<<endl;
break;
default: cout<<"Invalid Code"<<endl;
}
cout<<"Please enter one number: ";
cin>>Num1;
cout<<"Please enter a second number: ";
cin>>Num2;
}
cout << "Good Bye!";
return 0;
}
/* sample output
The first number is 1 and the second number is 2. Your sum is 3.
Please enter one number: 0
Please enter a second number: 1
1. +
2. *
3. /
4. -
Please indicate a code: 1
The first number is 0 and the second number is 1. Your sum is 1.
Please enter one number: 0
Please enter a second number: 0
Good Bye!
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.