Okay,
I have to create a menu ( which I did) and have 3 options. (done) In option A I have to allow the user to enter how many numbers he wants to input (a limit). Then after that limit of numbers is input, the user is told which number was the largest. This is the part that I'm having trouble with. All it prints for the value is what the last number that was entered was.
I'm getting the same error in section B. All it wants to display for the lowest number entered is -99... I think I have an idea for that one, but section A still gives me problems.
I have to use loops.. do..while, for, while, if / else. Any pointers as to what I'm missing here?
Code:// 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 MainMenu: 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; counter = 0; for (counter = 0; counter < limit; counter++) cin >> number; temp1 = 0; if (number > temp1) temp1 = number; if (temp1 != 0) cout << "\nYour largest number out of " << limit << " was " << temp1 << "." << endl; cout << endl; goto MainMenu; break; case 'b': case 'B': cout << " Enter a group of numbers. I will tell you the smallest number. \n Enter " << SENTINEL << " to exit." << endl; cin >> number; counter = 0; temp2 = 0; while (number != SENTINEL) { // open while 3 counter++; cin >> number; } if (number < temp2) temp2 = number; cout << "Your smallest number out of " << counter << " was " << temp2 << "." << endl; cout << endl; goto MainMenu; // added as a reroute to the main menu 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