Public Group

# Untitled

This topic is 3841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 to work i dont know where should i place and insert the rest of my code. i dont know what questions i should be asking myself can someone point me to what else i need so i can solve this what other items should i be needing to complete ? do i need a if or a while statement ? [edit: source block formatting -SiCrane] [Edited by - SiCrane on February 10, 2008 7:21:45 AM]

##### Share on other sites
To be honest, I don't know why greater-than and less-than signs sometimes format correctly in the source boxes, and sometimes don't. But, if you create a post and these symbols don't format correctly, I would make some effort to fix the problem so that your code is easier to read.

Also, it seems that soft tabs (spaces) format better than hard tabs; as such, I'd recommend converting hard tabs to soft tabs before posting code to the forums.

As for your question, whenever posting for help with an assignment of some sort, it would help us if you specified what it's for (e.g. school, self-directed study, etc.), so that we know how much help it's appropriate to offer.

1. It looks like you're using (early) C-style variable declarations (that is, all variables declared at the top of the function), but in C++ it's more idiomatic to declare and initialize variables where they're needed.

2. It looks like you have a constant for the number of values to be entered in option A, but the assignment seems to say that the user should enter this value.

3. To make things easier, I would create separate functions to handle the behaviors specified for options A and B; then, within the switch statement, simply call these functions.

4. For the functions themselves, just think through the desired behavior, and express it in code. That's a little simplistic, but nevertheless it's what you need to do. (Hint: You will need a loop of some sort for each option; however, the type of loops used will be different, since in one case you need to loop a known number of times, while in the other you need to loop until a particular value is entered.)

##### Share on other sites
Quote:
 Original post by jykTo be honest, I don't know why greater-than and less-than signs sometimes format correctly in the source boxes, and sometimes don't. But, if you create a post and these symbols don't format correctly, I would make some effort to fix the problem so that your code is easier to read.

The way that the forum database stores posts isn't round-trip safe. So things like < get stored in the database as &lt;. When you go to edit the posts you see the &lt; if the < is outside of a source block. Which means that if you forgot the source block to begin with and then add the source block, it turns from < to &lt; inside the source block. Fortunately, all you need to do to fix this is to edit the post and save the modifications without doing anything.

On the downside, if you actually have escaped HTML entities in your code the forum software will destroy them.

1. 1
2. 2
frob
15
3. 3
4. 4
5. 5

• 20
• 12
• 13
• 14
• 78
• ### Forum Statistics

• Total Topics
632142
• Total Posts
3004394

×