ok i have an assignement the assignment is to make a menu
with these selection
Write a program that displays a menu with the following choices to the user.
A - Find the largest # with a known quantity of numbers
B - Find the smallest # with an unknown quantity of numbers
C - Quit
Please enter your choice ___

If A is chosen, you should ask the user how many numbers he wants to enter. If he enters 5, you should read 5 numbers from him. You should then display the largest number he entered. Use a for loop to read these and display the largest.

If B is chosen, you should keep reading numbers no matter what until the user enters -99. Then you should display the smallest number he entered not counting the -99.

ok here is my code

#include <iostream>

using namespace std;

const int A_QUANTITY = 50;    //amount of #s entered for choice A
const int B_SENTINAL = -99;   //sentinal used to end choice B

int main()
{
	bool again = true;        //used to control main choice loop
	int letter;              //stores the choice made
	int bigger;               //stores current biggest #
	int smaller;              //stores current smallest #
	int temp;                 //stores next number for comparison
	int i;                    //controls the For loop

	while (again)
	{
		//displays instructions for main options
		cout << "What would you like to do?" << endl;
		cout << "(enter the letter of your choice)" << endl;
		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 - End this program." << endl;
		
		//choice 
		cin >> letter;

		do (letter >= 'A' && letter <= 'C')
			switch (letter)
		     {
			case 'A':
			
				cout << "Lets find the max numbers you entered " <<endl;
				break;
				
		    case 'B':
			
				cout << "Lets find the smallest numbers you entered" <<endl;
				break;

			case 'C':
				cout << "We are all done" <<endl;


	}// end of main

...i dont know what else i need as for the rest of the code casue i dont know where should i place and insert the rest of my code can someone point me to what else i need ?

You're getting there. What you need to do now is add code for cases 'A' and 'B'. Start with case 'A' as it's a bit simpler. Ask the user how many numbers they want to input, then loop for that amount. Inside the loop, grab a number from the user. Compare this to a variable that will hold the largest number. If the number the user entered is larger than the one in the variable, update it accordingly.

And by the way, this do() loop is unnecessary:

do (letter >= 'A' && letter <= 'C')

Just set again to false in case 'C'.

you say its not need my i ask why not ??? im not sure what you mean with "again" . im very new to this and hate to ask but is "again" a command function like if and do ??
should i change the do to an if statement ?

>you say its not need my i ask why not ???
I'm guessing you created it so that the program will exit when the user enters 'C'. However, this is unnecessary, because you've already implemented a while() loop in your program.

>im not sure what you mean with "again". again is the bool variable that you declared at the beginning of your program:

bool again = true;        //used to control main choice loop

In essence, you have a while() loop that keeps your program running. again is the condition, and it is what controls whether the while() loop should continue or not. When the user enters 'C', you should set 'again' to false. This will mean that your while loop will stop.

>you say its not need my i ask why not ???
I'm guessing you created it so that the program will exit when the user enters 'C'. However, this is unnecessary, because you've already implemented a while() loop in your program.

>im not sure what you mean with "again". again is the bool variable that you declared at the beginning of your program:

bool again = true;        //used to control main choice loop

In essence, you have a while() loop that keeps your program running. again is the condition, and it is what controls whether the while() loop should continue or not. When the user enters 'C', you should set 'again' to false. This will mean that your while loop will stop.

i think i need some sleep cause man im not even paying attention??

should i change it to an " if" statement ?

I have stripped down your progam to highlight changes that seem appropriate and entered comments where changes made.

int main()
{
  bool again = true;        
  char letter;              //change letter to type char, not type int

  while (again)
  {
     //displays menu
     cout << "What would you like to do?" << endl;
     cout << "(enter the letter of your choice)" << endl;
     cout << "A" << endl;
     cout << "B" << endl;
     cout << "C - End this menu." << endl;

     cin >> letter;

     switch(letter)
     {
       case 'A':		
           break;
       case 'B':		
           break;
       case 'C':
           //change variable called again so program will exit the loop
           again = false;
           break;
        default:  //handle inappropriate user input
           cout << "only enter A, B, or C" << endl;
           break;          
     } //add a } to close the switch statement 
  } //add a } to close while loop
}// end of main

ok i have this much of my code but i cant get why the largest number to cout for section 'A'

#include <iostream>

using namespace std;


#include <iostream>

using namespace std;


int main()
{
	bool again = true;        //used to control main choice loop
	char letter;              //stores the choice made
   


#include <iostream>

using namespace std;


int main()
{
	bool again = true;        //used to control main choice loop
	char letter;              //stores the choice made
   




 while (again)
  {


		//displays instructions for main options
		cout << "What would you like to do?" << endl;
		cout << "(enter the letter of your choice)" << endl;
		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 - End this program." << endl;
		
		//choice 
		cin >> letter;

		
		int count;
		int numbers;
		int largestNumbers;
			switch (letter)
		     {
			case 'A':
			case 'a':   
		
                               cout << "Lets find the max numbers you entered " <<endl;
	               cout << " How many numbers are we comparing ?"<< endl;
                                cin  >> count;


		



		if ( count > 0)
				{
		cout << "Please First number."<< endl;
	                cin >> largestNumbers;
				
				


		for (int i = 0; i < count-1; i++)
	{
					
		cout << "Please enter next number."<< endl;
		cin >> numbers;
	if (numbers > largestNumbers )
{					
               numbers = largestNumbers
					
	cout << "Your largest number entered number was "
	        << largestNumbers <<endl;
					}
				
				}
				
	      break;
				
	    case 'B':
	    case 'b':	
			cout << "Lets find the smallest numbers you entered" <<endl;


			break;

                    case 'C':
	    case 'c':



		cout << "We are all done" <<endl;
                                again = false;
  	

			break;
				default:  //handle inappropriate user input
           cout << "only enter A, B, or C Please" << endl;
           break;
			}
		}	
	}
return 0;
}
if (numbers > largestNumbers )
{					
   numbers = largestNumbers; // this is wrong

   cout << "Your largest number entered number was "
        << largestNumbers << endl;
}

You've got the assignment line backwards. It should be

largestNumbers = numbers;

The other thing is that you probably want to move the cout statement outside of the if() and for() blocks, this way it only prints the largest number after the user has finished entering all the numbers.

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