can any help me out? i'm fairly new at this c++ programming thing and i was wondering if there was anyway to make this program a little smaller or less repetitive where the result for the calculations are concerned, in the switch statement.
thanks
/* This program performs calculator functions.*/
#include <iostream.h>
#include <conio.h>
//constants for the menu
#define ONE 1
#define TWO 2
#define THREE 3
#define FOUR 4
#define FIVE 5
#define SIX 6
#define SEVEN 7
#define EIGHT 8
#define NINE 9
#define TEN 10
#define ELEVEN 11
#define TWELVE 12
void main() { //beginnning of program
//initialize variables
int choice=0;
int num1=0;
int num2=0;
while(choice!=TWELVE) { //beginning of while loop
clrscr();
cout<<endl;
cout<<" My Calculator - Menu"<<endl;
cout<<endl;
cout<<endl;
cout<<"\t[" <<ONE<< "] - Add"<<endl;
cout<<"\t[" <<TWO<< "] - Subtract"<<endl;
cout<<"\t[" <<THREE<< "] - Multiply"<<endl;
cout<<"\t[" <<FOUR<< "] - Divide"<<endl;
cout<<"\t[" <<FIVE<< "] - Remainder"<<endl;
cout<<"\t[" <<SIX<< "] - Less than"<<endl;
cout<<"\t[" <<SEVEN<< "] - Less than or equal to"<<endl;
cout<<"\t[" <<EIGHT<< "] - Greater than"<<endl;
cout<<"\t[" <<NINE<< "] - Greater than or equal to"<<endl;
cout<<"\t[" <<TEN<< "] - Equal to"<<endl;
cout<<"\t[" <<ELEVEN<<"] - Not equal to"<<endl;
cout<<"\t[" <<TWELVE<<"] - Quit"<<endl;
cout<<endl;
//prompts the user to input an operation and 2 numbers.
cout<<"Enter an operation: ";
cin>>choice;
/*this if statement tests the choice entered and terminates
the program if the selection 12 is entered.*/
if (choice==TWELVE) { //beginning of if statement
cout<<"Goodbye!"<<endl;
getch();
return;
} //end if
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
switch (choice) { //beginning of switch statement
case 1: {
cout<<"Result is: "<<num1+num2;
}
break;
case 2: {
cout<<"Result is: "<<num1-num2;
}
break;
case 3: {
cout<<"Result is: "<<num1*num2;
}
break;
case 4: {
cout<<"Result is: "<<num1/num2;
}
break;
case 5: {
cout<<"Result is: "<<num1%num2;
}
break;
case 6: {
if(num1<num2) {
cout<<"Result is: True";
}
else {
cout<<"Result is: False";
} //end if
}
break;
case 7: {
if(num1<=num2) {
cout<<"Result is: True";
}
else {
cout<<"Result is: False";
} //end if
}
break;
case 8: {
if(num1>num2) {
cout<<"Result is: True";
}
else {
cout<<"Result is: False";
} //end if
}
break;
case 9: {
if(num1>=num2) {
cout<<"Result is: True";
}
else {
cout<<"Result is: False";
} //end if
}
break;
case 10:{
if(num1==num2) {
cout<<"Result is: True";
}
else {
cout<<"Result is: False";
} //end if
}
break;
case 11:{
if(num1!=num2) {
cout<<"Result is: True";
}
else {
cout<<"Result is: False";
} //end if
}
break;
/* default: {
cout<<"Invalid Operation!"<<endl;
} */
} //end of switch statement
getch();
} //end of while loop
} //end of program