Hello,
I am having an issue with my program showing my eax registry value. I have been googling for 6 hours now and have not found the answer. Can someone help? Code is below. I know exactly where the value is being added and can even change it to 0, but that exits my loop. Should I be looking to change that value to something different. This is not homework just trying to learn C++. I found the error by debugging and pulling up the different debugging windows. Thank you in advance.
Code:
#include <iostream>
using namespace std;
int add ( int x, int y );
int sub ( int x, int y );
int multiply ( int x, int y );
int divide ( int x, int y );
int beerbottles ( int b );
int main ()
{
int i, b, x, y, z;
while ( i != 0 )
{
cout << "Choose an option below" << endl;
cout << "1. Hear a song." << endl;
cout << "2. Calculator." << endl;
cout << "Option:";
cin >> i;
cout << endl;
if ( i == 1 )
{
cout << "1) Add" << endl;
cout << "2) Subtract" << endl;
cout << "3) Multiply" << endl;
cout << "4) Divide" << endl;
cin >> z;
if ( z == 1 )
{
cout << "1st number to add: ";
cin >> x;
cout << "2nd number to add: ";
cin >> y;
int result = add( x, y );
cout << "Total is: " << result;
}
if ( z == 2 )
{
cout << "1st number to subtract: ";
cin >> x;
cout << "2nd number to subtract: ";
cin >> y;
int result = sub( x, y );
cout << "Total is: " << result;
}
if ( z == 3 )
{
cout << "1st number to multiply: ";
cin >> x;
cout << "2nd number to multiply: ";
cin >> y;
int result = multiply( x, y );
cout << "Total is: " << result;
}
if ( z == 4 )
{
cout << "1st number to divide: ";
cin >> x;
cout << "2nd number to divide: ";
cin >> y;
int result = divide( x, y );
cout << "Total is: " << result;
}
}
if ( i == 2 )
{
cout << "How many beer bottles are on the wall? ";
cin >> b;
cout << beerbottles( b );
}
}
}
int add ( int x, int y )
{
return x + y;
}
int sub ( int x, int y )
{
return x - y;
}
int multiply ( int x, int y )
{
return x * y;
}
int divide ( int x, int y )
{
return x / y;
}
int beerbottles( int b )
{
while ( b > 0 )
{
cout << b << " bottles of beer on the wall, " << b << " bottles of beer " << endl;
--b;
cout << "Take one down, pass it around, " << b << " bottles of beer on the wall." << endl;
cout << endl;
}
}