Post your code using code tags. You can find out how in the FAQ or just about any of the stickies. If you still can't figure it out, post your code anyway and a moderator will tag it for you (just this once though).
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
i guess your mistake is not using break; after each case... if you don't do this, your switch will run all the way until all the cases are done...
another thing i would advise you to do is use the default until the end of the switch statement, since this way you will not have this kind of problems...
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
you are pretty close to what is posting correctly your code... all you have to do identify the code you are using as c code ([[B]code=c[/B]]), and write your code with the right margins so it is easier to follow...
second, what your teacher means by putting the package in a loop is that, for example, if the user inputs the wrong package once, he will be able to input a wrong package the second time, and get away with murder... this is why you must do a while loop that checks if the user's answer is inside the boundaries of the package...
i recommend you do the same thing with the hours...
by the way... there's no need to do this:
case 'a':
case 'A':...
you can do it this way:
case ('a'||'A'):...
i'm sure narue will correct me if i'm wrong...
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
>you can do it this way:
>case ('a'||'A'):...
You can, but it won't work like you expect. ('a'||'A') is a boolean expression that evaluates to true. It's identical to:
case 1:
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
By the way, I'm still not sure if I followed the correct guidelines for piosting code. Please advise me if I have done something wrong. Thanks in advance.
Nope.
Problem 1: You didn't use CODE tags as the background of the input box advises. Also here
Problem 2: Formatting code
i'm sure narue will correct me if i'm wrong...
You're wrong :icon_razz:
If you aren't sure, it only takes a minute or two to test ideas like this one before posting and prevents Narue from having fun at your expense :icon_twisted:
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
but, it works with what lovetwins wants to do, since it will evaluate if package equals to 'a' or || 'A' ...
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
You're wrong :icon_razz:
If you aren't sure, it only takes a minute or two to test ideas like this one before posting and prevents Narue from having fun at your expense :icon_twisted:
:-/ I like it when narue makes fun of me... i don't know... maybe i'm a little wacked... but it just adds a little sense of humor to my day...:D
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
> but, it works with what lovetwins wants to do, since it will evaluate if package equals to 'a' or || 'A'...
No. It evaluates to case 1, so entering 'a' or 'A' would give the message 'Enter only a, b or c for package'.
~s.o.s~
Failure as a human
12,220 posts since Jun 2006
Reputation Points: 3,307
Solved Threads: 783
Skill Endorsements: 55
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
Because constant-expressions are evaluated in the case construct. True evaluates to 1, false evaluates to 0.
case (i + 1): //flag an error, requires constant expression
cout << "In error";
break;
case (3 + 3):
cout << "In case 6";
break;
case (3 == 0):
cout << "In case 0";
break;
case (3 == 3):
cout << "in case 1";
break;
~s.o.s~
Failure as a human
12,220 posts since Jun 2006
Reputation Points: 3,307
Solved Threads: 783
Skill Endorsements: 55
but, if you are evaluating a character, along with another one, say in this case is capital form, can't you do it with an or || expression?
case ('a'||'A')
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
No, because constant expressions are evaluated, and you end up with the expression 'a' || 'A' getting evaluated. Any conditional expression within the case construct would either evaluate to 0 or 1.
The way the OP had done it is the correct way. Either that, or convert the character accepted to lowercase and keep all lowercase characters in your case constructs.
~s.o.s~
Failure as a human
12,220 posts since Jun 2006
Reputation Points: 3,307
Solved Threads: 783
Skill Endorsements: 55
>but, if you are evaluating a character, along with another one, say in this
>case is capital form, can't you do it with an or || expression?
Um, did you not read the posts that told you (in reply to you!) that you can't do that and why it doesn't work? Because it seems a lot like what we say to you is going in one ear and right out the other.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
alright... alright... jeje...
it had been a long time since i got you mad at me huh narue?
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3
>it had been a long time since i got you mad at me huh narue?
If you want to get me mad, keep using jeje. It's a big pet peeve of mine. I used to play a game called X-wing vs. Tie Fighter and was actually one of the better players in the world. There was a club that insisted on speaking spanish (which was rude enough but we let it slide) and always (like, every sentence) used jeje or jaja. It annoyed me so much that I went out of my way to play games against them as much as possible to make sure they got raped on a regular basis. I'm not sure, but I think I was one of the reasons they disbanded.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
i'm sorry... please don't stop talking to me... :P
it's just that i'm used to laugh like that... but i'll do my best... okay?
Nichito
Posting Virtuoso
1,722 posts since Mar 2007
Reputation Points: 424
Solved Threads: 73
Skill Endorsements: 3