Thread: compiled c program, got weird error messages

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    17

    Angry compiled c program, got weird error messages

    My assignment was to write a program for an automatic teller machine that dispenses money. User should enter amount (some even multiple of ten) and the machine dispenses that amount using the least amount of bills. The machine stocks $50, $20, and $10 bills. I have to use a single function that will determine the number of each denomination of bills to dispense and the must send all three results back to the calling function using output (reference) parameters. I think they're called pointers in c. But yeah so I have a code I've been working on. It's all over the place but I think I have the general idea. I compile it and get this error message:

    /tmp/ccdM4LCy.o:money.c.text+0x1b): undefined reference to `GetInteger'
    collect2: error: ld returned 1 exit status


    ... Now I have no idea what that means. So some help would be nice

    Code:
       GNU nano 2.2.6                                                    File: money.c
    
    
    /* Program for automatic teller machine that dispenses money
    
    
       Written by Kim 
       October 2013
       Language: C (gcc target)
    */
    
    
    #include <stdio.h>
    
    
    /*Function prototypes*/
    int GetBills (int dollars, int* fifties, int* twenties, int* tens);
    void PrintBills(int dollars, int fifties, int twenties, int tens);
    
    
    int main()
    {
            int dollars, fifties, twenties, tens;
            printf("Enter dollar amount desired:\n");
            dollars = GetInteger();
            GetBills(dollars, &fifties, &twenties, &tens);
    }
    
    
    
    
    
    
    int GetBills(int dollars, int *fifties, int *twenties, int *tens)
    
    
    {
    
    
            *fifties = dollars / 50;
            *twenties = (dollars %= 50) / 20;
            *tens = (dollars %= 20) / 10;
            return *fifties || *twenties || *tens;
    }
    
    
    
    
    void PrintBills(int dollars, int fifties, int twenties, int tens)
    {
            printf("Dispensing %d dollars...", dollars);
            if(fifties)
                   printf("%d $50 bills\n", fifties);
            if(twenties)
                   printf("%d $20 bills\n", twenties);
            if(tens)
                   printf("%d $10 bills\n", tens);
            printf("\n");
    
    
    return ;
    
    
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Hey man.

    Great post, you've posted your code and you compiler's error messages. This puts you above the vast majority of most posters!

    On line 25 of your code you have 'dollars = GetInteger();'. Your compiler (well technically your linker) has no idea what or where this is, and neither do I.

    So where is GetInteger() defined?

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    17
    Hey thanks for answering. I got rid of that.. and I got rid of a lot of other stuff too.. This is how it looks now and I got it to compile.. Just have to check if it works. Here's the new code

    Code:
      GNU nano 2.2.6                                                    File: money.c
    
    /* Program for automatic teller machine that dispenses money
    
    
       Written by Kim V
       October 2013
       Language: C (gcc target)
    */
    
    
    #include <stdio.h>
    
    
    /*Function prototypes*/
    void GetBills (int dollars, int* fifties, int* twenties, int* tens);
    void PrintBills(int dollars, int fifties, int twenties, int tens);
    
    
    int main(void)
    {
            int dollars, fifties, twenties, tens;
            printf("Enter dollar amount desired:\n");
            GetBills(dollars, &fifties, &twenties, &tens);
    }
    
    
    
    
    
    
    void GetBills(int dollars, int *fifties, int *twenties, int *tens)
    
    
    {
    
    
            *fifties = dollars / 50;
            *twenties = (dollars %= 50) / 20;
            *tens = (dollars %= 20) / 10;
            return;
    }
    
    
    
    
    void PrintBills(int dollars, int fifties, int twenties, int tens)
    {
            printf("Dispensing %d dollars...", dollars);
            if(fifties)
                   printf("%d $50 bills\n", fifties);
            if(twenties)
                   printf("%d $20 bills\n", twenties);
            if(tens)
                   printf("%d $10 bills\n", tens);
            printf("\n");
    
    
    return ;
    
    
    }

  4. #4
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Not a bad attempt, however you're not actually getting the user's input, you're only asking for it!

  5. #5
    Registered User
    Join Date
    Oct 2013
    Posts
    17
    crap. so would I use a scanf statement?

  6. #6
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    You most certainly would!

    The rest of your code looks more or less correct so it should work ok once you fix that.

    Although don't forget to print the actual values at the end too!

  7. #7
    Registered User
    Join Date
    Oct 2013
    Posts
    17
    Ok thanks so much!

  8. #8
    Registered User
    Join Date
    Oct 2013
    Posts
    17
    Ok I'm back. I thought I had this one in the bag but guess not.. What do you mean by that last sentence? "Print the actual values..."

  9. #9
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Your main function is the entry point to your program and is the function that is executed.
    You aren't actually calling PrintBills anywhere! You have to output the result to the user somewhere!

  10. #10
    Registered User
    Join Date
    Oct 2013
    Posts
    17
    so in my main function I have to call on PrintBills somehow?

  11. #11
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Yes. In a similar way to how you have called GetBills in your main function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Turbo C based, Graphics program error
    By sidx64 in forum C Programming
    Replies: 8
    Last Post: 11-18-2012, 05:12 PM
  2. Weird command prompt error, program not working..
    By Shamino in forum C++ Programming
    Replies: 18
    Last Post: 10-30-2007, 11:32 AM
  3. Weird access to an exe compiled with windows.h
    By _izua_ in forum C++ Programming
    Replies: 8
    Last Post: 08-12-2007, 03:43 PM
  4. Weird error when running program
    By Rizage in forum C++ Programming
    Replies: 3
    Last Post: 10-25-2002, 06:41 AM
  5. VC 6.0 compiled error
    By alan4100 in forum Windows Programming
    Replies: 4
    Last Post: 09-17-2001, 03:10 PM

Tags for this Thread