Really confused. ):

This is a discussion on Really confused. ): within the C Programming forums, part of the General Programming Boards category; The user selects a character that is represented by a double (cost). The user then selects an int which represents ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    16

    Unhappy 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.

    Thank you for your time.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Rawr View Post
    How do I connect the two to perform the action above?
    Quote Originally Posted by Rawr View Post
    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.)

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    16
    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;
    			}
    			}
    		}
    	}
    
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    16
    So if I just do selection == 'p', it will take the capital and lower case?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Rawr View Post
    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.)

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    16
    Automatic True = Returns 1 if the amount is enough to cover the cost, 0 if there is not enough?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Rawr View Post
    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'.

  9. #9
    Registered User
    Join Date
    Feb 2010
    Posts
    16
    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?

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.

  11. #11
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    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.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This:
    Code:
    if( x == 'A' || x == 'a' )
    is not the same as this:
    Code:
    if( x == 'A' || 'a' )
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused with array size
    By desmond5 in forum C Programming
    Replies: 4
    Last Post: 12-04-2007, 05:14 PM
  2. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 04:29 AM
  3. Confused
    By jeev2005 in forum C Programming
    Replies: 5
    Last Post: 06-01-2006, 03:04 PM
  4. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 04:49 PM
  5. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 02:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21