So I have been plugging away at this program. I had to create a menu and have 3 sections. Section A asked for a limit, then the user enters that many numbers and it tells them which number was the largest. DONE that.
Section C quits the program.. that works too.
Section B however... supposed to let the user enter as many numbers as they want, inputing -99 when they are done. After this it tells them what the smallest number was. I've tried all sorts of things, but I either get a 0 answer or -99. What am I missing? I'm limited to loops or if / else statements.
HELP!
// Week 5 - Control Structures II- Philip McCrary - 11-08-06
#include<iostream>
using namespace std;
char menuItem;
int number;
int limit, counter;
int temp1, temp2;
const int SENTINEL = -99;
int main()
{ //open main
while (menuItem != 'C' || 'c')
{ // open while 1
cout << "Welcome to CS106 Week 5: Control Structures II." << endl;
cout << "Please choose from the following options below." << endl;
cout << "A: What's the largest number?" << endl;
cout << "B: What's the smallest number?" << endl;
cout << "C: Flee to Windows" << endl;
cout << "Please choose now: ";
cin >> menuItem;
cout << endl;
if ((menuItem >= 'A' || 'a') && (menuItem <= 'C' || 'c'))
{ // open if main
switch (menuItem)
{ // open switch 1
case 'a':
case 'A':
cout << "This section will find the largest number? " << endl;
cout << "How many numbers do you want to enter? ";
cin >> limit;
cout << endl;
cout << "Enter " << limit << " numbers: " << endl;
for (counter = 0; counter < limit; counter++)
{
cin >> number;
if (number > temp1)
temp1 = number;
}
cout << "\nYour largest number out of " << limit << " was " << temp1 << "." << endl;
cout << endl;
break;
case 'b':
case 'B':
cout << " Enter a group of numbers. I will tell you the smallest number. \n Enter " << SENTINEL << " to exit." << endl;
counter = 0;
while (number != SENTINEL)
{ // open while 3
counter++;
cin >> number;
{
cin >> number;
if (number < temp2)
temp2 = number;
}
}
cout << "Your smallest number out of " << counter << " was " << temp2 << "." << endl;
cout << endl;
break;
case 'c':
case 'C':
cout << " Goodbye. " << endl;
return 0;
} //close switch 1
} // close if main
else
{
cout << "Please enter a valid menu option; A, B, or C." << endl;
cin >> menuItem;
cout << endl;
} // end else
} // close while 1
return 0;
} // close main