# need some home work help

This topic is 3594 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 ? someone named "jyk" made a comment on my other ,post but i didnt under his comment
Quote:
 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
can some one break that down for me ? [/source] [Edited by - Sneftel on February 10, 2008 8:52:28 AM]

##### Share on other sites
Edit the tags in your post, it's not displaying correctly.

Search for 'For' and 'While' loops in C++. That might get you on the right track.

##### Share on other sites
From the stickied FAQ:

Do not ask homework related questions. The Gamedev.net members are not here to answer your homework questions, its against the forum rules and few people take kindly to it. Besides, we shouldn't need to tell you that figuring it out for yourself will be way more beneficial to you in the long run.

##### Share on other sites
if i dont ask for the help , how can i figure out myself ?

im not a genuis or anything . again im new to C++ and i dont know how to figure it out on my own . i didnt ask for someone to finish it i just want to know where to go from here.

i mean i did figure that much of the code on my own

##### Share on other sites
If it's a homework question, the point of homework is to improve your knowledge of the things you've studied in class. You will more than likely have been provided with all the materials you need to complete the task, it's just understanding them that will get you to where you need.

##### Share on other sites
Quote:
 Original post by shadowfire36if i dont ask for the help , how can i figure out myself ?im not a genuis or anything . again im new to C++ and i dont know how to figure it out on my own . i didnt ask for someone to finish it i just want to know where to go from here.i mean i did figure that much of the code on my own

Well, the code you have already shouldn't require much critical thinking so you didn't really do anything. Basically the important part of the assignment is figuring out what to do for A, B, and C. Now, it so happens that if you can figure out the B section then A doesn't really require any additional thought. Likewise, if you figure out A, then figuring out B is much easier.

A common trick to solving problems is to take the problem and solve it for a small set. Like, if someone said find the largest of the next 2 numbers, how would you do that? Next, you need to find the largest of the next 3 numbers. How would you do that? How about 4 numbers?

That's about all the help I think you can get without being given the answer. Good luck.

##### Share on other sites
I have done such programs in class, not very complex. You will have to practice little bit. Use for-loop and arrays. Compare array index with each other and you can get the result [wink]

##### Share on other sites
Right now, your question is completely unfocused. It's along the lines of: "here's my assignment, tell me what I should be doing right now". That's just a bit too much. You'll get better help if you focus your questions down into something specific. Also, make sure you put in some common sense. There's no point in writing additional code if what you have is broken.

Here's what I see you have so far: You have a menu system that doesn't even work right at the beginning.

const int A_QUANTITY = 50 Aren't you supposed to ask the user for how many numbers he wants to enter? So why do you have a constant instead?
int letter; This is C++ code you are writing, not C. Why is a letter an int here? This is not simply a stylistic choice. Your code will later on fail, because the user will type in a character, and your code tries to deal with it as an int.
int i;Don't predeclare your loop variables like this in C++. You can create the variables in the for loop, or right before the for loop. I recommend within the loop so you don't leave a bunch of loop variables lying around, or at least in a more logical location, like right before a for loop. Right now, it just serves as code clutter.
while (again) Use a do-while loop instead.
cin >> letter; Fails because, as I mentioned earlier, you created letter as an int. Also, as a serious programmer, you would want error checking on this user input. Just FYI, because in production code, I would expect to see that. Don't bother with error checking now, just fix the mistakes.
do (letter >= 'A' && letter <= 'C') Logical misstep. Why would you create an inner do-while loop? Next, why compare letter to 'A' and 'C' when you have a switch statement doing precisely that anyway?

Other notes: Watch your indentation. Sloppy indentation is a sign of bad and sloppy coding. Which leads to mistakes. Which leads to wasted time on time-consuming but minor mistakes. Your code won't also compile because you don't close the braces properly. Here's a hint on matching braces and parens: when you open a brace or parens, always type the closing one immediately after. That way you don't forget.

Your code doesn't compile at the moment. However, your question was simply "homework help". That is, you didn't even bother to test compile your code. Not a good sign.

##### Share on other sites
Hi m8,

ALthough I havent much posts on gamedev this is a new account and I have used gamedev alot in the past.

People generally hate folk asking for answers to homework questions as the struggle and the extra reading you have to do to get the answer is what makes your programming skills increase.

I dont know if youve done this but talking generally if you have heaps of code and it just isnt working , basically think of it as a mess and break it down........copy and paste your main fucntion into another file , get a printf or cout in it depending on what c library your using and print hello world, test

Next add your first function , before you add any code put a printf("Test <function name> \n") just to see the function is getting called before you start adding anything. Next if you have variables comming into the function from a call from main then inside the function do a printf immediatly and see if the proper value is comming out of the variable, if its not working or your getting gobbldygook then STOP , do not code other functions as you will just create a spaggeti mess and make things harder to track down.

This may seem remedial to what your trying to achieve as the end result but I actually finished my HND and it took alot of work and you must get code in C tested a line at a time when testing when your starting out. (I saw 3/4 of my class fail because they werent thinking along these lines)

Get in effect your basic program template with all the functions and parameters and test each of the blank functions out by passing the parameters into respective printfs, then work on function 1 fully and test test test. Only when you are 100% sure one parts working move onto the next part as C has an uncanny knack of compiling making things look good but the start results are botched all the same.

(Ok I see your using C++ cout so substitute where Ive said printf for cout)

Just with a brief look at the code you submitted , looks like you have to go back to basics and make sure yopur use case is working correctly - check your semi colon and bracer placements.

Finally
good luck

##### Share on other sites
i guess that the problem im really not understanding is how can i ask the user to enter how many numbers he wishs to enter i have never seen or done anything with that type of input , is there a way to make represent infinite ?

##### Share on other sites
#include <iostream>using namespace std;const int A_QUANTITY = 50;    //amount of #s entered for choice Aconst int B_SENTINAL = -99;   //sentinal used to end choice Bint 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;					switch (letter)		        {			case 'A':							cout << "Lets find the max numbers you entered " <<endl;//call function or code immediatly underneath here to do the desired thing//perhaps use cin >> varA to get the value you want relevant to the string A				break;						    case 'B':							cout << "Lets find the smallest numbers you entered" <<endl;//call function or code immediatly underneath here to do the desired thing//perhaps use cin >> varB to get the value you want relevant to the string B				break;			case 'C':				cout << "We are all done" <<endl;//call function or code immediatly underneath here to do the desired thing//perhaps use cin >> varC to get the value you want relevant to the string C                                break;                       }//end of switch        }//end of while}// end of main

Im a bit rusty on C and theres probably alot more elegant ways to do it but I dodnt see how you needed that if statement since you have a switch statement, also theres still alot you need to do but the first thing is to get your structure correct and make sure the switch performs correctly for a single iteration before trying to add loops and what not. If you did this you would see the variable letter is declared as an int but you are comparing it in the switch to letters A, B , C which are strings.

I apologise if anythings wrong but its been a while since I used C , however should

int letter;

NOT BE

char letter;

?

Anyways stick at it :) I dont want to get into trouble on the forums since its against the rules to help out and also test test at least 5 to 10 times with basic data and no fancy loops in your switch until you see its handling the input of a letter and when it executes the correct cases, THEN move onto something else.

There is probably a much more elegant way but the point Im trying to get across fix the basics and test, checkout google for cout and see how you use it to display variables , cout is your friend for testing . Just to be completely clear with the above ammendments the program will still not work , you need to go over your sheets on variables and functions and if there are any small example programs try getting those to work. Ow and use small comments detailing what should happen after every conditional branch off that way you can follow the logic of where your program has succesfully executed to and use couts at every 2 to 5 lines if you have to ; to test values arent being corrupted and if they are you know more or less at which point the prog is botched.

Finally and this is just my personal preferance when developing small programs , that is dont go using overly complicated 1 line expressions if it would be easier to understand by breaking it up. (I always used to go for code optimisation at the very end of my program once I knew it was working correctly and was well tested - granted this may not be the way to go in big apps but it helps when starting out). Another thing is use google if your not sure of syntax, if it doesnt show on the first 5 pages , change your search and be prepared to spend a good few hours or more of just searching if you wnat to get anywhere.

[Edited by - firefly28 on February 10, 2008 3:29:45 PM]

##### Share on other sites
Quote:
 Original post by shadowfire36i guess that the problem im really not understanding is how can i ask the user to enter how many numbers he wishs to enter i have never seen or done anything with that type of input , is there a way to make represent infinite ?
What do you mean by 'make represent infinite'?

As for asking the user how many numbers he or she wishes to enter, I think you may have to ask a more specific question (you're already using cin for user input, so I'm not sure what part of asking the user to specify how many values to enter is proving to be problematic).

Also, your posts would be a bit easier to read with proper capitalization, spelling, and punctuation. (Developing good writing style will also help in your programming, as the skills required - accuracy and attention to detail - are equally applicable to both areas.)

##### Share on other sites
Quote:
 Original post by MJPFrom the stickied FAQ:Do not ask homework related questions. The Gamedev.net members are not here to answer your homework questions, its against the forum rules and few people take kindly to it. Besides, we shouldn't need to tell you that figuring it out for yourself will be way more beneficial to you in the long run.

Uh oh. I am guilty of this. I go to school online as its my only option so the internet is pretty much my classroom. If I cant find it on google or in my book I have to ask since I am in a way different time zone then the rest of the class. I think it should be allowed as long as its a legitimate question and your not doing the homework for someone.

The OP looks like hes pretty much done with the code or at least contributed a big part of his assignment already. I dont see the problem with providing a little help. I could understand if he had nothing written. (Sorry OP Im new too and cant provide you with help to your problem.)

##### Share on other sites
Theres still a fair bit to be done and alot of basics not adhered to, so the best bet is google to verify if the basic structure is correct + get yer sheets out hehe !!!!

Also being a person that did 100% of my HND myself it was bloody hard work. I was in a class where a portion of them used to blatently copy sheets and pass some assesments while having no clue about them so I can see why gamedev doesnt allow it.

Heres the thing I have actually done some OS development in the past all be it on a very small scale and I am off some use as a Software Developer or even tech support but its so hard to get jobs now and people copying and such are devalueing the qualification so I can understand why gamedev has immplemented this rule. In my country an HND Soft Dev was a sure thing for a job but I know people that have coastered their qualification , they go to jobs screw it up so the job then ups their criteria to a degree thus keeping many competant people out of jobs. Sorry to be blunt but Im in quite a small town and thats the way I see it.

I dont mind people getting guidance but I also have had people phone me for old HND assignments and it is annoying considering the whole purpose of the qualification is too expand ones mind/educate and you wont get that by getting things handed on a plate.

[On a lighter note I can see someone quoting this when I have questions about my latest gaming project haha)

##### Share on other sites
sorry the problem im having is trying to figure out
is how to allow to the user to make his own input and unlimited .

up to this point i have defined how many inputs the user is allowed ,
i was thinking of a psuedo code some thing like this:

num1>num2 = larger
num2>num2 = larger

that is what i know how to do,

but i havent seen nor read anything to where i can have the user give me what he the amount wants, and then store the number largest number .

so if the user selects "A" the im not sure on how to ask him " please enter how many digits for comaprison " then cout >> only the variable stored peoperly

##### Share on other sites
see who says you guys aint helping me out !!

int main(){	bool again = true;        //used to control main choice loop	char letter;              //stores the choice made while (again)  {//displays instructions for main optionscout << "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;		             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;               again = false;               break;		}	}return 0;}

[Edited by - shadowfire36 on February 10, 2008 4:04:26 PM]

##### Share on other sites
Your formatting is still all messed up. Can you fix the formatting and re-post the code in a [ source ] box?

##### Share on other sites
i got the majority of the code down , but i cant get to display the largest number for option '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;}

}

##### Share on other sites
Quote:
 Original post by shadowfire36i got the majority of the code down , but i cant get to display the largest number for option 'A'*** Source Snippet Removed ***
Ok, I'm going to try this one more time...

Your posted code is still all messed up. You've double-pasted the first part of the file, there are some extra characters floating around, and you have a brace outside the [ source ] block. Also, your indentation is completely borked (again, I recommend replacing tabs with spaces before posting code to the forums).

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628686
• Total Posts
2984237

• 16
• 13
• 13
• 10
• 10