Computer Science, asked by poojasingh3084a, 1 year ago

WAP in switch to calculate 4 function(sum,sub,multiplication,division) in C++?

Answers

Answered by Muskan5785
1
I have to make a C Program calculator with choices: 0 - exit, 1 - add, 2 - subtract, 3 - multiply and 4 - divide.Once the user inputs their choice, I ask for two numbers from them.I need to use functions for each arithmetic operation.When I'm done with calculating, it should go back to the menu.The program only ends when the user chooses 0.
Answered by Yashika853649
1
#include<iostream>
using namespace std;
int main(){
int choice;
cout<<"Press 1 for addition
2 for subtraction
3 for division
4 for multiplication
0 for exit";
cin>>choice;

while(1){. //infinite while loop, exit when user //enter0
switch(choice)
{
case 0:
exit();
break;
case 1:
int a,b;
cout<<"Enter two operand for addition operation";
cin>>a>>b;
cout<<a+b<<endl;
break;

case 2:
int a,b;
cout<<"Enter two operand for subtraction operation(bigger number first)";
cin>>a>>b;
cout<<a-b<<endl;
break;

case 3:
int a,b;
cout<<"Enter two operand for division operation(dividend first then divisor)";
cin>>a>>b;
cout<<b/a<<endl;
break;


case 4:
int a,b;
cout<<"Enter two operand for multiplication operation";
cin>>a>>b;
cout<<a*b<<endl;
break;

}
}
return 0;

}

Yashika853649: the menu that i wrongly provided outside the while loop, please put that inside the while loop
Similar questions