C++ Program to design a Five Function Calculator using Switch/Case
#include <iostream.h>
#include <conio.h>
int main () {
main:
int a,b,c,d,ans;
double v1, v2, ans2;
char yn;
while (yn != 'n')
{
clrscr();
cout<<"\n\n\n\t-_-_-_-_-_-_-_-_- Five Function Calculator _-_-_-_-_-_-_-_-_\n\n";
cout<<"Select the operation .\n";
cout<<"1. Multipication\n";
cout<<"2. Division\n";
cout<<"3. Subtraction\n";
cout<<"4. Addition\n";
cout<<"5. Power\n";
cout<<"6. Exit\n";
cout<<"Enter a number: [1-6]";
cin>>ans;
switch (ans) {
case 1:
goto multipication;
break;
case 2:
goto division;
break;
case 3:
goto subtraction;
break;
case 4:
goto addition;
break;
case 5:
goto power;
break;
case 6:
cout<<"Thank You\n";
return 0;
}
multipication:
cout<<"\n\t\t==================Multipication===============\n";
cout<<"Enter your First Number: ";
cin>>v1;
cout<<"Enter your Second Number: ";
cin>>v2;
ans2=v1 * v2;
cout<<"Answer: "<<ans2<<"\n\n";
cout<<"Would like to solve another one <yn>: ";
cin>>yn;
goto main;
return 0;
division:
cout<<"\n\t\t==================Division===============\n";
cout<<"Enter your First Number: ";
cin>>v1;
cout<<"Enter your Second Number: ";
cin>>v2;
if (v2==0) {
cout<<"ERROR!!! You cannot divide anything by 0\n\n";
goto main;
}
ans2=v1 / v2;
cout<<"Answer: "<<ans2<<"\n\n";
cout<<"Would like to solve another one <yn>: ";
cin>>yn;
goto main;
return 0;
subtraction:
cout<<"\n\t\t==================Subtraction===============\n";
cout<<"Enter your First Number: ";
cin>>v1;
cout<<"Enter your Second Number: ";
cin>>v2;
ans2=v1 - v2;
cout<<"Answer: "<<ans2<<"\n\n";
cout<<"Would like to solve another one <yn>: ";
cin>>yn;
goto main;
return 0;
addition:
cout<<"\n\t\t==================Addition===============\n";
cout<<"Enter your First Number: ";
cin>>v1;
cout<<"Enter your Second Number: ";
cin>>v2;
ans2=v1 + v2;
cout<<"Answer: "<<ans2<<"\n\n";
cout<<"Would like to solve another one <yn>: ";
cin>>yn;
goto main;
return 0;
power:
cout<<"\n\t\t==================Power===============\n";
cout<<"Enter a number: ";
cin>>v1;
cout<<"Enter the Power: ";
cin>>v2;
ans2=v1;
for(int i=2; i<=v2; i++)
ans2 = ans2 * v1;
cout<<"Answer: "<<ans2<<"\n\n";
cout<<"Would like to solve another one <yn>: ";
cin>>yn;
goto main;
return 0;
}
return 0;
}
Related Posts : C++ Programs
0 comments:
Post a Comment