coin problem

This is a discussion on coin problem within the C Programming forums, part of the General Programming Boards category; I am trying to do a coin problem but I can't seem to get it to work. When I complie ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    coin problem

    I am trying to do a coin problem but I can't seem to get it to work. When I complie it, there are no errors and the program lets me enter a number and then does nothing. I can't figure out what I did wrong and if anyone can point me in the right direction it would be very appricaited.
    Code:
    #include <stdio.h>
    
    int main()
    
    
        {
        	int total=0;
        	int quart=0;
        	int dime=0;
        	int nick=0;
        	int pen=0;
        	
    
            	{
            		printf ("\n Enter the total (in cents): ");
            		scanf(" %d, &total");
            		quart = total/25;
            		total = total - (quart * 25);
            		dime = total/10;
            		total = total - (dime * 10);
            		nick = total/5;
            		total = total - (nick * 5);
            		pen = total;
            		scanf("\n The change is:"  );
            		if(quart != 0)
            			printf("\n %d qaurters ", quart );
            		if(dime != 0)
            			printf("\n %d  dimes.", dime);
            		if(nick != 0)
            			printf("\n %d nickels", nick);
            		if(pen != 0)
            			printf("\n %d pennies ", pen);       
    		}
    	return 0;
    	}

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Code:
    scanf("\n The change is:"  );
    Print the message, not try to read it.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,234
    Quote Originally Posted by et1wilson View Post
    I am trying to do a coin problem but I can't seem to get it to work. When I complie it, there are no errors and the program lets me enter a number and then does nothing. I can't figure out what I did wrong and if anyone can point me in the right direction it would be very appricaited.
    Code:
    #include <stdio.h>
    
    int main()
    
    
        {
        	int total=0;
        	int quart=0;
        	int dime=0;
        	int nick=0;
        	int pen=0;
        	
    
            	{
            		printf ("\n Enter the total (in cents): ");
            		scanf(" &#37;d, &total");
            		quart = total/25;
            		total = total - (quart * 25);
            		dime = total/10;
            		total = total - (dime * 10);
            		nick = total/5;
            		total = total - (nick * 5);
            		pen = total;
            		scanf("\n The change is:"  );
            		if(quart != 0)
            			printf("\n %d qaurters ", quart );
            		if(dime != 0)
            			printf("\n %d  dimes.", dime);
            		if(nick != 0)
            			printf("\n %d nickels", nick);
            		if(pen != 0)
            			printf("\n %d pennies ", pen);       
    		}
    	return 0;
    	}

    1) I don't understand the braces I've marked in red, above.

    2) After getting the cents, you would normally want a while loop for each type of coin:
    Code:
    while(total >= 25)   {
        quarters++;
        total -= 25;
    }
    Repeat the above for each type of coin. There is no need for multiplication or division, just addition of the type of coin, and subtraction from the total.

    Ez smeezy! << and *how* are you spelling quarters?? >>

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    new problem

    Ok I now have fixed it and chnaged a few things and get it to display the information but it is all 0.00000. What can I do to fix it?
    Code:
    #include <stdio.h>
    
    int main()
    
    
        {
        	int total=0;
        	int quart=0;
        	int dime=0;
        	int nick=0;
        	int pen=0;
        	
    
            	{
            		printf ("\n Enter the total (in cents): ");
            		scanf(" %d, &total");  		
            		
            		printf("\n The change is:"  );
            		if(quart != 0)
    				quart = total/25;
            			total = total - (quart * 25);
            			printf("\n %f qaurters ", quart );
            		if(dime != 0)
    				dime = total/10;
            			total = total - (dime * 10);
            			printf("\n %f  dimes.", dime);
            		if(nick != 0)
            			nick = total/5;
            			total = total - (nick * 5);
            			printf("\n %f nickels", nick);
            		if(pen != 0)
    			pen = total;
            			printf("\n %f pennies ", pen);       
    		}
    	return 0;
    	}

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Print the values as ints.

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    Code:
    scanf(" &#37;d, &total");
    That a typo? Maybe it should be:
    Code:
    scanf(" %d", &total);
    I used to be an adventurer like you... then I took an arrow to the knee.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. permutations based problem
    By Zeeshan in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2001, 09:13 AM

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