Why is my program not working ?
Code:
here my program:
#include<iostream>
using namespace std;
int main()
{
//Declare Variables
char operation = ' ';
int num1 = 0;
int num2 = 0;
int answer = 0;
//Input Items
cout<<"Enter A(Add),S(Subtract),M(Multiply) or D(Divide):";
cin>>operation;
operation = toupper(operation);
cout<<endl;
cout<<"Enter the first number:";
cin>>num1;
cout<<"Enter the second number:";
cin>>num2;
cout<<endl;
//Calculate and Display Output
switch(operation)
{
case 'A':
answer=num1+num2;
cout<<"Answer:"<<answer<<endl;
break;
case 'S':
answer=num1-num2;
cout<<"Answer:"<<answer<<endl;
break;
case 'M':
answer=num1*num2;
cout<<"Answer:"<<answer<<endl;
break;
case 'D':
answer=num1/num2;
cout<<"Answer:"<<answer<<endl;
break;
default:
cout<<"Error"<<endl;
} //end switch
system("PAUSE");
return 0;
} //End of Program
1. i want it to display an error message if any letter other than a,s,d,m is entered( it shouldnt ask for two numbers)
2. for my case 's' , i want it to swap the number(subtracting second number from first number) but only if the first number is larger or equal to the second number.
3. for my case 'd'. i want it to divide larger number by smaller number always.
*** i have read my text book over and over again and i cant seem to figure it out** please help me =]