Well, it calculates, it just won't loop, or exit right. . .
I've tried a lot of things, I just don't know why it won't work right. So please help me.
Code:
#include <iostream>
int addition ( int x, int y )
{
return x + y;
}
int subtraction ( int x, int y )
{
return x - y;
}
int multiplication ( int x, int y )
{
return x * y;
}
int division ( int x, int y )
{
return x / y;
}
using namespace std;
int add();
int sub();
int mul();
int div();
int main()
{
int input, z;
z = 0;
do
{
cout<<"1. Add\n2. Subtract\n3. Multiply\n4. Divide\nE. Exit\nEnter your choice: ";
cin>> input;
switch ( input ) {
case 1:
add();
break;
case 2:
sub();
break;
case 3:
mul();
break;
case 4:
div();
break;
case 'E':
( z + 1 );
break;
default:
cout<<"Error: Unknown Input\n";
break;
}
return 0;
} while ( z != 1 );
}
int sub(){
int x, y;
cout<<"Enter the first number to subtract: ";
cin>> x;
cin.ignore();
cout<<"Enter the second number to subtract: ";
cin>> y;
cin.ignore();
cout<<"The difference is: "<<subtraction ( x , y );
cout<<"\n";
return 0;
}
int add(){
int x, y;
cout<<"Enter the first number to add: ";
cin>> x;
cin.ignore();
cout<<"Enter the second number to add: ";
cin>> y;
cin.ignore();
cout<<"The sum is: "<<addition ( x, y );
cout<<"\n";
return 0;
}
int mul(){
int x, y;
cout<<"Enter the first number to be multiplied: ";
cin>> x;
cin.ignore();
cout<<"Enter the second number to be multiplied: ";
cin>> y;
cin.ignore();
cout<<"The product is: "<<multiplication ( x, y );
cout<<"\n";
return 0;
}
int div(){
int x, y;
cout<<"Enter the first number to be divided: ";
cin>> x;
cin.ignore();
cout<<"Enter the second number to be divided: ";
cin>> y;
cin.ignore();
cout<<"The quotiant is: "<<division ( x, y );
cout<<"\n";
return 0;
}
When I make Exit '5' instead of 'E' it works, but it says, "Press any key to continue." I have tried the 'while' loop, but when I do it I get a black screen. I don't know why it's not working, so please help me with this.