Answer to Question #15438 in C++ for zyrus
2012-09-27T08:04:07-04:00
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
1
2012-09-27T12:15:41-0400
#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 !
Learn more about our help with Assignments:
C++
Comments
Leave a comment