creating a coin counting in c

This is a discussion on creating a coin counting in c within the C Programming forums, part of the General Programming Boards category; I am writing a program in c . The idea is to give a money value ;i.e. 2,75 and the ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    5

    creating a coin counting in c


    I am writing a program in c . The idea is to give a money value ;i.e. 2,75 and the program must give an output which will be the minimum number of coins (quarters,dimes,nickels,pennies) needed to reach the above value.
    My code is the following:
    Code:
    #include <stdio.h>
    #include <math.h>
    Code:
    int main(void) 
    {
        printf("Give an amount: ");
         int n;
         int d; 
    }
        do
    {
            printf("non-negative numerator:");
            n = GetInt();
    }
        while (n < 1);
        do
    {
            printf("positive denominator: ");
            d = GetInt();
    }
    {
        while (d < 1);
        float a = (n / d);
        printf("%.2f \n", a);
    }     
    int (cent , nickle , dime ,penny ,sum);
    do
    {
             cent = round(n * 100);
             while (cent >= quarter);
    
    
                 cent = (cent - quarter);
                 count++;
    
    
             while (cent >= dime);
    
    
                 cent = (cent - dime);
                 count++; 
    
    
             while (cent >= nickle);
    
    
                 cent = (cent - nickle);
                 count++;
    
    
             while (cent - penny);
    
    
                 cent = (cent - penny);
                 count++;
             printf("%d",count);     
        // ​??????????????????
        return 0;
    }
    Can anyone help me to complete the code and make it run properly, because I'm confused?

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Code:
    int (cent , nickle , dime ,penny ,sum);
    This makes no sense.

    Also you use getInt() function, but you haven't implemented it somewhere.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    What must I do in order getInt function make sense

    Quote Originally Posted by std10093 View Post
    Code:
    int (cent , nickle , dime ,penny ,sum);
    This makes no sense.

    Also you use getInt() function, but you haven't implemented it somewhere.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    Can you tell me how the sum of coins will work?

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    "getInt" function is used at CS50 classes and to use it you must #include <cs50.h>
    And of course you must use their CS50 appliance as your compiler for it to recognize this header file.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    Thank you

    I modified the code as:
    Code:
    int main(void) 
    {
        printf("Give me an amount: ");
    
    
    }
    
    
    
    
    void change(int *pennies, int *nickels, int *dimes, int *quarters);    
    do
    {
             cent = round(n * 100);
             while (cent >= quarter);
    
    
                 cent = (cent - quarter);
                 count++;
    
    
             while (cent >= dime);
    
    
                 cent = (cent - dime);
                 count++; 
    
    
             while (cent >= nickel);
    
    
                 cent = (cent - nickel);
                 count++;
    
    
             while (cent - penny);
    
    
                 cent = (cent - penny);
                 count++;
             printf("%d",count);     
        
        return 0;
    }
    Does it make any sense

  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by vag3621 View Post
    Does it make any sense
    No.

    There are so many problems that I recommend rereading your book/tutorial/other learning resource.

    Bye, Andreas

  8. #8
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    Hi,

    I was working on the same problem, but luckily it is now resolved.
    You will find my code on this site in the thread called "Whats wrong with my code".
    It is now on the first page of this forum but may be pushed down by the time you read this.
    You will also find very similar code here: greedy.c - danieleugenewilliams - Dan&#39;s Projects - Google Project Hosting
    Between these two codes you should be able to find pointers to write your own.

    Good luck.
    Kamil

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Coin counting program in c
    By vag3621 in forum C Programming
    Replies: 3
    Last Post: 11-08-2012, 05:19 AM
  2. Coin Counting Program Problems
    By kevinandrewsun in forum C Programming
    Replies: 3
    Last Post: 06-02-2012, 10:34 AM
  3. Coin Counting Program
    By woodyhavoc in forum C Programming
    Replies: 8
    Last Post: 03-14-2011, 02:15 AM
  4. Another Coin Counting Program
    By MipZhaP in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2005, 01:02 AM
  5. Coin counting (logic problem)
    By xlokix in forum C++ Programming
    Replies: 47
    Last Post: 01-20-2005, 02:22 PM

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