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

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions