Jump to content
  • Advertisement
Sign in to follow this  
shadowfire36

need some home work help

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by shadowfire36
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


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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!