Read the tutorial about switches they allow you to make long if statements.
Here is an example of my code:
Code:
#include <iostream>
int multiply(int x,int y)
{
return x*y;
}
int divide(int x, int y)
{
return x/y;
}
int add(int x, int y)
{
return x+y;
}
int subtract(int x, int y)
{
return x-y;
}
using namespace std;
int main()
{
char op='c';
int x,y;
while (op!='e')
{
cout<<"What operation would you like to perform add(+), subtract(-),divide(/),multiply(*), (e)exit?";
cin>> op;
switch(op)
{
case '+':
cout<<"Enter the numbers you would like to add."<<endl;
cin>>x;
cin>>y;
cout<<x<<"+"<<y<<"="<<add(x,y)<<endl;
break;
case'-':
cout<<"Enter the numbers you would like to subtract."<<endl;
cin>>x;
cin>>y;
cout<<x<<"-"<<y<<"="<<subtract(x,y)<<endl;
break;
case'/':
cout<<"Enter the numbers you would like to divide."<<endl;
cin>>x;
cin>>y;
cout<<x<<"/"<<y<<divide(x,y)<<endl;
break;
case'*':
cout<<"Enter the numbers you would like to multiply."<<endl;
cin>>x;
cin>>y;
cout<<x<<"*"<<y<<multiply(x,y)<<endl;
break;
case'e':
return 0;
default:
cout<<"sorry, try again."<<endl;
}
}
return 0;
}
case replaces if which makes everything a lot easier.
As for the else loop I don't know why it won't work.