Hey guys, I was doing my reading last night and was trying to come up with a program other than the practice assignments. It has been hard remembering all the keywords when they are given to you in the practice assignment. I came up with one and kinda got myself in a corner which is good because it is making me think and I am starting to remember these key words better. This is my first C++ class so I might be getting ahead of myself, just say so if I am. I am learning about switch, case, if, and else and I ran into this problem. In the practice assignment we are only working with two possible routs for the case switch. for example:

What type of customer are you <R or B>?

switch (customerType)

case 'R':
case 'r':
blah blah blah......................

case 'B':
case 'b':
blah blah blah......................

So I was coming up with a practice of my own that was about a restaurant, it asks:

Did the customer have drinks from the bar(Y or N):
Did the customer have appetizers (Y or N):
Did the customer have dessert (Y or N):

If they answer Yes to any question they get some more questions reffering to that subject, which I know how to do, what I don't know how is if they answer No, is there a way to make it skip to the next question without me having to type the script everytime they answer No or Yes. I know there has to be a way where I only type out everything once, right? I can do it on the algorithim ;) I know that is the hardest part and takes a very intellegient person to draw the lines haha if someone could, please show me an example of how to make it skip to another part of the code. I probably just haven't got to it yet in class but I would like to know anyway.

Recommended Answers

All 10 Replies

Try an IF statement.

If that doesn't help, you'll have to post your code so we can actually see what you're trying to do.

You really need to put break after each case implementation.

To WaltP:
I don't have the code, I mean I started it last night but it is not finish or correct for that matter. Is there not a skip function? I know the "if" and "else" but I don't understand how that would help. Granted I probably just have not gone far enough in class yet. Is there a way to say "if this skip to this".

to Zhelih:
Really? Why? My book and teacher did not say anything about that. Is it just for organization? cosmetics?

Yes you can use continue/break/return/exit/goto.

To WaltP:
I don't have the code, I mean I started it last night but it is not finish or correct for that matter.

Oh, OK. We'll just wait for you to finish it correctly so you can post the code. But then, you won't need our help, will you? :icon_rolleyes:

Have you read any of the recommended posts, like the Rules and the thread titled Read Me: Read This Before Posting?

to Zhelih:
Really? Why? My book and teacher did not say anything about that. Is it just for organization? cosmetics?

If they didn't, you need a new book and a new teacher. Look again.

to WaltP:
Sarcasim is Anger's Ugly cousin WaltP ;) I understand though, I will post the code I have soon as I get home. I am also sure I read over the break after each case implementation, I will go back to that part of my book. To your last statement, I have read the rules and the read me, I do not believe I am in violation of anything as I did not find a post anywhere on this, I am sure I am using the wrong keywords for the search though. I am not expecting nor do I want you to trype the code for me, just looking for the keyword as itjelp showed.

to ithelp:
Thanks for your post, I did some research on the different options and it looks like goto will be the best one for this instance. However, I also read that goto is not well liked by programmers as it can make "spaghetti" code. I will try using that in the code and will post it when I get home.

to WaltP:
Sarcasim is Anger's Ugly cousin WaltP ;)

Oh, give me a break! :icon_rolleyes: Sarcasm is/can be a humorous way to get a point across when someone isn't listening. You would have laughed it this wasn't your post! :icon_wink:

I understand though, I will post the code I have soon as I get home. I am also sure I read over the break after each case implementation, I will go back to that part of my book.

Good, because it's in there

To your last statement, I have read the rules and the read me, I do not believe I am in violation of anything as I did not find a post anywhere on this,...

True, there are no violations. But you want help on your code. From the Read Me thread:

Keep the code short and sweet!

As much as we don't care, people insist on posting pages and pages of irrelevant code. Keep the code as short as possible. If the code isn't short, make it short by cutting out as much irrelevant code as possible. Ideally, we expect you to write a small test program that exhibits the problem you're having.

Granted, Narue didn't explicitly say "post your code", but isn't the implication quite strong? If we can't see your code, we can't tell you what's wrong with it.

commented: A funny guy! +1

True, there are no violations. But you want help on your code. From the Read Me thread:

Keep the code short and sweet!

As much as we don't care, people insist on posting pages and pages of irrelevant code. Keep the code as short as possible. If the code isn't short, make it short by cutting out as much irrelevant code as possible. Ideally, we expect you to write a small test program that exhibits the problem you're having.
Granted, Narue didn't explicitly say "post your code", but isn't the implication quite strong? If we can't see your code, we can't tell you what's wrong with it.

Yes it is implied quite strongly, oh.......what is this:

switch (customerType)

case 'R':
case 'r':
blah blah blah......................

case 'B':
case 'b':
blah blah blah......................

Now granted blah blah blah is not in my C++ Book or taught by my prof. It was my genius mind that came up with the syntax ;) I thought this would be enough to show what I was trying to do, I will go back and grab my full code for you though. By the way, I was laughing and this is my post. I wouldn't say Sarcasim is/can be a humourous of getting a point across, its more of an art and should not be applied unless you are fully trained and capable of using its full potential.

case 'R':
case 'r':
/*blablabla*/
break;

Please put break ok?

Ok.....I was confused on what zhelih was saying earlier about the break; I thought he was refering to a null line between the actual case statements. Anyways....I have run into a thumper on an actual homework assignment and I have decided to put this issue on a back burner until I get through my assignments. I am assuming I should start a new thread for a different problem. I am also going to go ahead and close this thread as I am sure future homework assignments will answer my question. zhelih and WaltP I hope you will have the time to help me with my other thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.