Thread: help with change program

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    help with change program

    Hi everyone. This is my 3rd program I have ever written in C and I am needing some help. The objective is to display the total number of coins for each type, the monetary value by type, the total monetary value for all coins, and the total number of all coins. I don't really know if I am doing this right. I was hoping someone could lead me in the right direction in the "Option B" part of my program. First of all, I keep coming up with the error message
    error C2144: syntax error : 'int' should be preceded by ';'

    but I cannot figure out where it is actually talking about it. I would appreciate any suggestions to lead me in the right direction. Thank you in advance.
    Allison
    Code:
    <#include <stdio.h>			
    #include <stdlib.h>			
    #include <conio.h>						
    #include <string.h>			
    #include <ctype.h>	
    #include <time.h>
    
    
    #define MAX 5
    
    void display_menu();			
    char get_choice();			
    
    void option_A();			
    void option_B();			
    
    
    void main()					
    {							
      char choice;				
    	do						
    	{							
    	  display_menu();				
    	  choice = get_choice();	
    								
    	  switch(choice)			
    	  {							
    	   case 'A':					
            option_A();				
    		break;					
           case 'B':				
    		option_B();				
    		break;					
          }							
    	} while(choice != 'C');		
    }								
    
    void display_menu()				
    {								
     system("cls");					
    								
     printf("\n~~Select one of the following options~~\n\n"); 
     printf("A-------Option A-The Magic Number!\n");			
     printf("B-------Option B-Counting Change!\n");			
     printf("C-------Quit\n");			
    }									
    						
    char get_choice()				
    {								
     char ch;						
     do								
     {								
      ch = toupper(_getch());		
    							
     } while (!strchr("ABC",ch));	
    						
    								
     return ch;						
    }								
    
    
    
    void option_A()		
    
    {
     int magic,               
         guess,               
         tries = 0;           
    
     srand( (unsigned)time( NULL ) ); 
     magic = rand()%MAX;              
     system("cls");
    
     printf("\n\nGuess the random number from 0 to %d\n\n",MAX);
     do
     {
    	printf("guess: ");
    	scanf_s("%d",&guess);
    	if(guess == magic)
    	{
    	 printf("** Right **");
    	 printf("%d is the magic number\n", magic);
    	}
    	else
    	if (guess > magic)
    	 printf(".. Wrong .. Too High\n");
    	else
    	 printf(".. Wrong .. Too Low\n");
    	tries++;
     } while(guess != magic);
    
     printf("You took %d tries.\n", tries);
     printf("\n\n\n\nPress any key to return to the main menu!"); 
     _getch();
    }
    						
    
    								
    
    
    void option_B()					
    							
    int count()
    
    {
        double num;
        double pennies;
        double quarters;
        double dimes;
        double nickels;
    	double half;
    	
        printf("Enter pennies amount: \n");
    	scanf_s("%d",pennies);
    	printf("Enter quarters amount: \n");
    	scanf_s("%d",quarters);
    	printf("Enter dimes amount: \n");
    	scanf_s("%d",dimes);
    	printf("Enter nickels amount: \n");
    	scanf_s("%d",nickels);
    	printf("Enter half dollar amount: \n");
        scanf_s("%d",half);
       
         quarters = (num * .25);
    
         dimes = (num * .10);
         
         nickels = (num * .05);
    
         pennies = (num * .01);
    
    	 half = (num * .50);
    
    
         printf ("Your amount contains the following");
         printf ("quarters:   " ,quarters);
         printf ("dimes:    " ,dimes);
         printf ("nickels:    " ,nickels);
         printf ("pennies:    " ,pennies);
    	 printf ("Half dollars:", half);
    
         scanf_s("%d", &num);
         return 0;
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    void option_B()					
    							
    int count()
    
    {
        do
    The top line there.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    reply about my question

    Isn't "do" considered a loop? I don't think a loop would be necessary in what I am trying to do. Sorry I am just confused with that.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    do is a loop, yes. Which do do you think shouldn't be there, and why?

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    loop

    I am just confused on why this should be a loop. I just want it to take the user input and convert it into the money value. I am still getting this error that I really don't understand where it is talking about. Do you know what this could be talking about and why?

    error C2144: syntax error : 'int' should be preceded by ';'

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    Oh and the part I am having problems with is the Option B part. I have the Option A part working fine. I just get errors on the B part. That is what I am confused about why it is not working. Sorry for not making that known in the last post.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's no loop anywhere near your option B, so I don't know why you see that as an issue. And that first line still needs to be inside the braces.

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    No the reason why I was talking about the loop was because the first reply from the user quzah said to put do. That is what I was talking about with the loop. I do have the first line inside braces? Am I not seeing something that you are seeing? Sorry about the confusion.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, this is a mess!
    Move the curly brace, right up under the name of the function.

    int count() is wrong, replace it with int count;

    Replace all the double datatype's with int's. You'll never get .21 of any coin, without a hell of a saw.

    Your scanf() already is set for integers, anyway, with %d

    You'll need to add a double sum variable, for the total amount of money, if you're printing that total amount, in this function.

    Are you supposed to be asking the user to tell you how many coins, and of which type, they want you to list?

    I'm sure it's wrong to ask them "how many quarters?", and then just print up
    "You have N quarters".

    Code:
    void option_B()					
    							
    int count()
    
    {
        double num;
        double pennies;
        double quarters;
        double dimes;
        double nickels;
        double half;
    	
        printf("Enter pennies amount: \n");
        scanf_s("%d",pennies);
        printf("Enter quarters amount: \n");
        scanf_s("%d",quarters);
        printf("Enter dimes amount: \n");
        scanf_s("%d",dimes);
        printf("Enter nickels amount: \n");
        scanf_s("%d",nickels);
        printf("Enter half dollar amount: \n");
        scanf_s("%d",half);
       
         quarters = (num * .25);
    
         dimes = (num * .10);
         
         nickels = (num * .05);
    
         pennies = (num * .01);
    
         half = (num * .50);
    
    
    
         printf ("Your amount contains the following");
         printf ("quarters:   " ,quarters);
         printf ("dimes:    " ,dimes);
         printf ("nickels:    " ,nickels);
         printf ("pennies:    " ,pennies);
         printf ("Half dollars:", half);
    
         scanf_s("%d", &num);
         return 0;
    
    }
    Num is a variable that you are never using, so don't ask for it.

    EXACTLY, think about what you want to do in this function, and list them:

    1)
    2)
    3)

    That will help you to organize your thoughts on it.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by f4ichick02 View Post
    No the reason why I was talking about the loop was because the first reply from the user quzah said to put do. That is what I was talking about with the loop. I do have the first line inside braces? Am I not seeing something that you are seeing? Sorry about the confusion.
    Code:
    void option_B()					
    							
    int count()
    
    {
    If you think "int count" appears after the curly brace there's not much we can do for you.

  11. #11
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    I appreciate that help. I understand what your talking about with this comment "I'm sure it's wrong to ask them "how many quarters?", and then just print up
    "You have N quarters". " That is why I I am calculating the number entered(num) * the value of the coin and then have it displayed. Or at least that's what I thought was correct.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by f4ichick02 View Post
    I appreciate that help. I understand what your talking about with this comment "I'm sure it's wrong to ask them "how many quarters?", and then just print up
    "You have N quarters". " That is why I I am calculating the number entered(num) * the value of the coin and then have it displayed. Or at least that's what I thought was correct.
    I'm sure you have misunderstood the assignment, or you're mixing what you want in one function, with what you want in another function.

    What *EXACTLY* do you want to do in this function? Right now num* (value of each coin), is helpful, but the variable "pennies" can do the same thing:

    quarters = num * 25 is backwards, btw. It's

    num = quarters * 25, or

    pennies = pennies + (quarters * 25)

    Because you need some logic to use a variable (pennies or num), to hold the values of each coin AND ADD IT TO THE PREVIOUS VALUE IT HAD BEFORE.

    Like a "running" sub-total kind of thingy.

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by f4ichick02 View Post
    Isn't "do" considered a loop? I don't think a loop would be necessary in what I am trying to do. Sorry I am just confused with that.
    What part of TOP LINE was hard to understand in my post?


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program to calculate change return.
    By OrAnGeWorX in forum C Programming
    Replies: 15
    Last Post: 11-17-2008, 09:49 AM
  2. type casting?
    By greatonesv in forum C Programming
    Replies: 12
    Last Post: 10-22-2008, 08:21 PM
  3. Replies: 2
    Last Post: 09-04-2001, 02:12 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM