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; }
Comments
Leave a comment