I wrote a switch program that performs 4 basic math operations:
#include <iostream.h>
int main(){
int ch;
float m1,m2,mt,d1,d2,dt,a1,a2,at,s1,s2,st;
cout<<"Please select a number from the menu\n";
cout<<"1. Multiplication\n";
cout<<"2. Division\n";
cout<<"3. Addition\n";
cout<<"4. Subtraction\n";
cin>>ch;
switch (ch)
{
case 1:
cout<<"Please enter the 1st of the 2 numbers to multiply\n";
cin>>m1;
cout<<"Please enter 2nd of the 2 numbers to multiply\n";
cin>>m2;
mt = m1*m2;
cout<<"The total is "<<mt<<"\n";
break;
case 2:
cout<<"Please enter 1st of the 2 numbers to divide\n";
cin>>d1;
getnum:
cout<<"Please enter 2nd of the 2 numbers to divide\n";
cin>>d2;
if (d2 == 0){
cout<<"Invalid Number, Try again (don't use 0)\n";
goto getnum;
}
dt = d1/d2;
cout<<"The total is "<<dt<<"\n";
break;
case 3:
cout<<"Please enter the 1st of the 2 numbers to add\n";
cin>>a1;
cout<<"Please enter 2nd of the 2 numbers to add\n";
cin>>a2;
at = a1+a2;
cout<<"The total is "<<at<<"\n";
break;
case 4:
cout<<"Please enter the 1st of the 2 numbers to subract\n";
cin>>s1;
cout<<"Please enter 2nd of the 2 numbers to subtract\n";
cin>>s2;
st = s1-s2;
cout<<"The total is "<<st<<"\n";
break;
}
return 0;
}
Can anybody tell me what I should do in order for the program to ask if you wish to perform any further calculations. If YES, how do I make it, so that the given answer will be taken as the first number to be used in the next calculation. and NO ends it. Any help would be greatly appreciated. THX



LinkBack URL
About LinkBacks



.