# Really confused. ):

• 03-26-2010
Rawr
Really confused. ):
The user selects a character that is represented by a double (cost).

The user then selects an int which represents another double (deposit).

Based off which character the user choose determines the cost.

Based off which int the user selected determines the deposit.

I must take the given deposit and minus it from the cost.

The then choose another int to represent a different deposit, and minus it from cost.

This continues until the deposit exceeds or equals the cost.

And this has me very, very confused.

I made a if/else statement for the characters, and gave each character a cost. (the menu)

I have then made another menu with a switch for the integers and assigned them to their deposits.

How do I connect the two to perform the action above?
I simply don't know where to start.
I know i need a loop; and am thinking a do-while loop.
But frankly... would like an example, or something to go by.

• 03-26-2010
tabstop
Quote:

Originally Posted by Rawr
How do I connect the two to perform the action above?

Quote:

Originally Posted by Rawr
I must take the given deposit and minus it from the cost.

Providing us with the answers to your questions makes our jobs easier, and we thank you for that.

(Although it is important to remember that - is not symmetric, and that really you want to subtract the cost from the deposit, and not the other way around.)
• 03-26-2010
Rawr
It's not working at all.
Every time I enter my code it does a run time error half way through as soon as I get to this part,
and tells me a bunch of junk isn't int'd when it is.

I have to be doing it wrong.
And thus need another way of addressing the problem.
Somehow this is wrong.

Code:

```if (selection == 'p'||'P')         {                 amount = 1;                 change = 0;                 if(total >= cost1)                 {                         change = total - amount;                 }                 else                 {                 }                 if (selection == 'c'||'C')         {                 amount = 2;                 change=0;                 if(total >= cost2)                 {                         change = total - amount;                 }                 else                 {                 }                         if (selection== 'b'||'B')         {                 amount = 3;                 change=0;                 if(total >= cost3)                 {                         change = total - amount;                 }                 else                 {                 }                         if (selection== 'n'||'N')         {                 amount = 4;                 change=0;                 if(total >= cost4)                 {                         change = total - amount;                 }                 else                 {                 }                         if (selection== 5)         {                 amount = cost5;                 change=0;                 if(total >= cost5)                 {                         change = total - amount;                 }                 else                 {                 }                         if (selection == 'o'||'O')         {                 amount = cost6;                 change=0;                 if(total >= cost6)                 {                         change = total - amount;                 }                 else                 {                 }                         }                         }                 return 0;                         }                         }                 }         } }```
• 03-26-2010
tabstop
Code:

`selection == 'p'||'P'`
Despite your wishes, this does not check whether selection is either 'p' or 'P'; it checks to see whether either of the conditions "selection == 'p'" or "'P'" is true. And since "'P'" is true, it doesn't really matter what selection is.
• 03-26-2010
Rawr
So if I just do selection == 'p', it will take the capital and lower case?
• 03-26-2010
tabstop
Quote:

Originally Posted by Rawr
So if I just do selection == 'p', it will take the capital and lower case?

Of course not. If you want to test two things, then test two things. Don't test one thing, and then use an automatic true for the other. (Each side of || must stand on its own.)
• 03-26-2010
Rawr
Automatic True = Returns 1 if the amount is enough to cover the cost, 0 if there is not enough?
• 03-26-2010
tabstop
Quote:

Originally Posted by Rawr
Automatic True = Returns 1 if the amount is enough to cover the cost, 0 if there is not enough?

What? You had an automatic true in your code, namely and to wit, 'P'. 'P' is always true. You were not, at any point, comparing your variable to 'P'.
• 03-26-2010
Rawr
No, I don't have an automatic true. Wanted to know if I was right in what an automatic true was.

I'm in intro to C, all this is new to me.

Can you give me a light example of an automatic true?
• 03-26-2010
tabstop
An example of an automatic true? It's the bit in big red letters below:
Code:

`if (selection == 'c'||'C')`
'C' is automatically true. READ carefully: You are not comparing the value of selection to 'C'. The variable selection does not appear in the expression. All you have is 'C', and 'C' is true.
• 03-26-2010
claudiu
What tabstop is saying is that you should determine the truth of comparing selection to 'c' and determine the truth of comparing selection to 'C'. Right now you are only doing the first part.
• 03-26-2010
quzah
This:
Code:

`if( x == 'A' || x == 'a' )`
is not the same as this:
Code:

`if( x == 'A' || 'a' )`
Quzah.