if (choice == 'a')
{
// Ask user how many numbers
while (counter < limit) // I would use a for loop, but this works too
{
// Get the numbers
++counter;
}
// Print highest number
}
elseif (choice == 'b')
{
// And so on and so forth
}
program still stops cold after trying to set the limit variable wont even ask for the numbers to try an get to the limit. I am lost here and the b option will only allow a single number to be entered and returns a not entered number for the output on it. The only option that works correctly is c the exit option. I need this to compare a series of numbers also and it doesn't do that. It also will not change the variables to the input variables.
Took that completely out of the current program. so I could advance and see what it would do, even though it is supposed to be how the supposed loop is to be ended and return the user to the menu.
#include <iostream>
#include <cctype>
usingnamespace std;
int main()
//set variables
{
int highnum(0);
int lownum(100);
int limit(0);
char choice;
int counter(0);
int num;
cout<< "A - Find the largest number with a known quantity of numbers. ";
cout<< endl;
cout<< "B - Find the smallest number with an unknown quantity of numbers. ";
cout<< endl;
cout<< "C - Quit";
cout<< endl;
cout<< "Enter your choice. ";
cin>> choice;
cout<< endl;
if(choice=='a')
{
cout << " How many numbers would you like to compare? ";
cin >> limit;
++ counter;
cout << endl;
cout<< "Enter your number ";
cin >> num;
if (num > highnum)
cout << "your highest number was ";
cout << highnum << endl;
}
if (choice == 'b')
{
cout << "Enter your numbers. ";
cin >> num;
cout<< "Your lowest number was ";
cout << lownum << endl;
}
if (choice == 'c')
cout << "thank you for playing. " << endl;
cin.get();
cin.get();
return (0);
}
Let me show you where the loop goes for choice A.
Afterwards, see if you can figure out how to do choice B.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if (choice=='a')
{
cout << " How many numbers would you like to compare? ";
cin >> limit;
//while (counter < limit) { // Do not put a semicolon after the while!
++ counter;
cout << endl;
cout<< "Enter your number ";
cin >> num;
// If num is bigger than current highest number (highnum)
// then set the highest number to num
//}
if (num > highnum) // Get rid of this line
cout << "your highest number was ";
cout << highnum << endl;
}