63 132
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #15438 in C++ for zyrus

Question #15438
Write a C++ program that would accept two numbers and will accept only characters based on the selection below, otherwise display “invalid input” and ask the user to try again. After accepting those characters, the program will perform the specific operation and the answer will be displayed.

Sample Output:
First Number : 7 Second Number : 4

< + > Addition < * > Multiplication
< – > Subtraction < / > Division

Enter choice: * <enter>
The answer is: 28

Expert's answer
#include <iostream>
using namespace std;
int main()
{

&
float n,k,a,z;
char q;
z=0;
a=0;
cout<<"First Number : ";
cin>>n;
cout<<"Second Number& : ";
cin>>k;&
while(z<1){
cout<<"Enter choice: ";
cin>>q;
switch(q)
{
& case '-' : {
a=n-k;
z=3;
break;
}
case '/' : {
a=n/k;
z=3;
break;
}
case '*' : {
a=n*k;
z=3;
break;
}
case '+' : {
a=n+k;
z=3;
break;
}
&
& default : cout<<"invalid input\n";

}
}
cout<<"The answer is: "<<a<<"\n\n";

system("PAUSE");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions