![]() |
Need help for C++ programming
Hi,
My name is Lori and I am in beginning programming and need help with an assignment. The program is C++ and the problem is listed below. I have tried everything I can think of but the program run indefinitely. Please help! Create a program that displays the registration information for programming seminars. The price per person depends on the number of people a company registers. (For example, if a company registers four people, then the amount owed by that company is $400.) The following chart shows the charges per registrant. Code:
Here is my program (that does not work): Code:
#include <iostream> |
Re: Need help for C++ programming
You've only posted half the code. Please post the entire program.
|
Re: Need help for C++ programming
Whoops! That would be a problem. Also the program does not end when the user enters "S" or "s" and when I enter 3 under the number of registrants, the computer gives an error message. The program just isn't working right and I am at my wits end. :wacky:
Here is the entire program: Code:
|
Re: Need help for C++ programming
For what values of company do you think company != 'S' || company != 's' will evaluate FALSE? Think about it carefully. "S or s" is *not* the correct answer.
|
Re: Need help for C++ programming
Would it be "S && s"?
|
Re: Need help for C++ programming
No, it would be a list of values. For instance if you thought the answer was "a, b and c", then you would answer "a, b and c", or "a, b or c" - exact syntax doesn't matter. So "S && s" is just as wrong as "s or S".
In thinking carefully, split the equation into two parts and evaluate each part, then evaluate the overall. So if you are considering 'z' for example, first evaluate "company != 'Z'" (true), then evaluate "company != 'z'" (false), then put them together and evaluate "true or false" (true). The obvious place to start is with S and s, so what is "company != 'S'", "company != 's'", and the results of those OR-ed together. Also lookup the word "carefully" in the dictionary. Your response was anything but a carefully thought out answer: you just assumed I was being pedantic about syntax, which I wasn't. |
Re: Need help for C++ programming
loop problem :
while (company != 'S' || company != 's'){...code...} this mean: while the statement (company != 'S' || company != 's') is true execute the code company!='S' means if company is not equal with S company != 's' means if company is not equal with s || means or.if any of the statements is true execute the code. lets see what happens if i enter S for company. 1) company!='S' ---->false 2) company != 's' ---->true 3) or --->true,continue executing the code. solution ========= && means and.if both statements are true execute the code. so from the above we get while (company != 'S' && company != 's') |
Re: Need help for C++ programming
xpi0t0s,
I truly meant no disrespect and did not mean to leave the impression that I am not trying to understand all of this. The fact is, is that I have been going over this same program for over a week with very little help from my teacher. It is all starting to look the same and my head starts swimming everytime I look at it. Maybe I just need to delete it all and start over. I appreciate you trying to help and explain things, but I didn't really understand the way that you went about it. Thank you for your help. Would you like to help me start it from the beginning again? |
Re: Need help for C++ programming
virxen,
Thank you, I think I get that part now. |
Re: Need help for C++ programming
No, I don't think you should start it from the beginning again. I was just trying to help you think through the logic: whenever you are using negative logic it gets confusing quickly, particularly because English works the way you did it, so for example "it's not a donkey or a sheep" is actually expressed as "it's not a donkey AND it's not a sheep". Every animal, including donkeys and sheep, is "not a donkey OR not a sheep":
cat: not a donkey=TRUE; not a sheep=TRUE; TRUE+TRUE=TRUE (+=OR) donkey: not a donkey=FALSE; not a sheep=TRUE; FALSE+TRUE=TRUE sheep: not a donkey=TRUE; not a sheep=FALSE; TRUE+FALSE=TRUE shonkey: not a donkey=FALSE; not a sheep=FALSE; FALSE+FALSE=FALSE so the expression only evaluates FALSE for an animal that is both a donkey and a sheep, i.e. "not a donkey" and "not a sheep" are both FALSE. So that is why your loop would never exit. Every character you entered was not S or not s, including both S and s. |
| All times are GMT +5.5. The time now is 20:36. |