I get the program to run but no matter what choice i make it comes up with -99 to exit...

#include <iostream>

using namespace std;

const int A_QUANTITY = 10;
const int B_SENTINEL = -99;

int main ()
{
bool again = true;
char choice;
int biggest = 0;
int smallest = 0;
int temp;
int i;



while (again)
{
// Displays instructions to user
cout << "A - Find the largest # with a known quantity of numbers" << endl;
cout << "B - Find the smallest # with an unknown quantity of numbers" << endl;
cout << "C - Exit" << endl;
cout << "Please enter your choice" << endl;

// Gets input from user
cin >> choice;

if (choice == 'B' || 'b')
{
i = 0;
do
{
cout << "Enter number: (-99 to exit)" ;
//cin >> i;
i++;

cin >> temp;
//cout << "You entered: " << temp << endl; //<< "\n"

if(i == 1)
smallest = temp;

if(smallest > temp && temp !=-99)
smallest = temp;

}while (temp != B_SENTINEL);

cout << endl << smallest << endl;
}

else if (choice == 'A' || 'a')
{
for( i = 0; i < 10; i++)
cout << "i = " << i << endl;

}

else if (choice == 'C' || 'c')
again = false;
}

return 0;
}

Please use code tags when posting code to this board.

You need to do multiple comparison's like this:

if(choice == 'B' || choice == 'b')

The three instances of that error is the only thing I see when looking quickly over your code.

Yep, the error is caused by the way that you have tried (admirably, but ultimately incorrectly) to catch people trying to use both upper and lower case. The solution given by Lerner should have solved this.

The reason that it occurs is because by having the condition if(temp == 'B' || 'b') you are asking the program to execute the code in the if-statement if temp is equal to 'B' or if 'b'. A statement like 'b' ALWAYS returns true (since the char 'b' is represented in memory as some non-zero, i.e. true, value), it's like saying if(1) .

This article has been dead for over six months. Start a new discussion instead.