#include <iostream>
using namespace std;
const int B_SENTINEL = -99; //sentinal used to end choice B
int main()
{
// variables
bool again = true; //used to control main choice loop
char choice; //stores the choice made
int large ; //stores # user inputs
int largest = 0; //stores current biggest #
int temp = 0; //stores next number for comparison
int i; //controls the For loop
int num = 0; //stores #'s user inputs
int small; //stores # user inputs
int smallest; //stores current smallest #
int next = 0; //stores next number for comparison
while (again == true)
{
//displays instructions for main options
cout << "What would you like to do?" << endl;
cout << "Please Enter the letter of your choice and click Enter" << endl;
cout << "A - Find the largest # within a known quantity of #s" << endl;
cout << "B - Find the smallest # within an unknown quantity of #'s"<< endl;
cout << "C - Quit this program." << endl;
cout << "Please enter your choice" " ";
//obtains choice user inputs
cin >> choice;
cout <<endl;
if (choice == 'A' || choice == 'a')
{
// asks user to enter how many numbers they would like to enter
cout <<"Please enter how many #'s you would like to enter:" <<" ";
cin >> num;
cout <<endl;
cout <<endl;
// lets the user know how many numbers user chose to enter
cout <<"The # you entered was:" <<" ";
cout << num << " " <<endl;
// tells user how many number to enter
cout << "Please enter " <<num << " #'s an click Enter." <<endl;
cout << "Please use spacebar to input spaces between each number." <<endl;
cin >> large;
largest= large;
for ( i = 0; i < num - 1; i++)
{
// Read in a number, overwriting previous number read in
cin >> temp;
}
if (temp > largest)
{
largest = temp;
//output of largest number entered
cout << "The largest number entered was: ";
cout << largest << endl;
cout <<endl;
cout <<"Please enter next # to see if it is larger than " << largest <<" " <<endl;
cin >>temp;
}
if (largest < temp)
{
// outputs this if this # is largest
cout << "The largest # now is: " << temp <<endl;
cout <<endl;
}
else if (largest > temp)
{
// outputs if this is # is larger then temp
cout << "The largest # now is: ";
cout << largest;
cout <<endl;
}
}
else if (choice == 'B' || choice == 'b')
{
// ask user to input #'s and tells them to input -99 to exit to main menu
cout << "Enter #'s to find the smallest # you enter then click Enter:" <<endl;
cout <<"To exit to main menu please input: " << B_SENTINEL <<" and click Enter." << endl;
cout <<"Please space #'s using spacebar" <<endl;
cin >> small;
smallest = small;
//start of sentinel controlled while loop
while (next != B_SENTINEL)
{ cin >> next;
if (smallest > next)
{
smallest = next;
//output of smallest number entered
cout << "The smallest number entered was: " <<endl;
cout << smallest << endl;
}
}
}
// closes the program
else
return 0;
}
}
what I am getting now is for a it works fine if I put the largest number in last but lets say i inter for choice Please enter how many #'s you would like to enter: I put 6 here then ask me to enter my 6 numbers and I do 23 56 12 36 69 1
and says my largest number is 23 what am I missing here