Answer to Question #70283 in C++ for Kelera

Question #70283
Write a program that accepts two real numbers and a select code from a user. If the entered select code is 1, have the
program add the two previously entered numbers and display the result; if the select code is 2, the numbers should be
multiplied; and if the select code is 3, the first number should be divided by the second number.
1
Expert's answer
2017-09-28T01:38:23-0400
#include <iostream>
using namespace std;
int main()
{
double a,b; // two real numbers
int selectCode;
cout<<"Enter real number A= ";
cin>>a;
cout<<"\nEnter real number B= ";
cin>>b;
cout<<"\nEnter select code (1, 2 or 3): ";
cin>>selectCode;

switch (selectCode)
{
case 1:
cout<<"\nA+B= "<<a+b<<endl;
break;
case 2:
cout<<"\nA*B= "<<a*b<<endl;
break;
case 3:
if(b!=0)
cout<<"\nA/B= "<<a/b<<endl;
else
cout<<"\nA/B Error! B cannot be Zero "<<endl;
break;

default:
cout<<"\nSelect code must be 1, 2 or 3 "<<endl;
}

cout<<endl;
return 0;
}

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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS