"assignment makes integer from pointer without a cast"

This is a discussion on "assignment makes integer from pointer without a cast" within the C Programming forums, part of the General Programming Boards category; that error came up in my gnu compiler.... repeatedly. Here's the code: Code: #include <stdio.h> void first_prn(); float charge_counter(int *); ...

  1. #1
    Freez3L
    Guest

    "assignment makes integer from pointer without a cast"

    that error came up in my gnu compiler.... repeatedly.
    Here's the code:

    Code:
    #include <stdio.h>
    
    void first_prn();
    
    float charge_counter(int *);
    
    int main(void)
    
    {
     int a=725, b=115, c=600, d=327, e=915, f=1011, g=47, *q;
     int i=1;
     int total;
     int charge;
     *q = &a;
    first_prn();
    
    printf("       123              725                  $ %f \n", ++i, charge_counter(q));
    *q = &b;
    total = charge;
    printf("       205              115                  $ %f \n", ++i, charge_counter(q));
    *q = &c;
    total=total+charge;
    printf("       464              600                  $ %f \n", ++i, charge_counter(q));
    *q = &d;
    total=total+charge;
    printf("       596              327                  $ %f \n", ++i, charge_counter(q));
    *q = &e;
    total=total+charge;
    printf("       601              915                  $ %f \n", ++i, charge_counter(q));
    *q = &f;
    total=total+charge;
    printf("       613              1011                 $ %f \n", ++i, charge_counter(q));
    *q = &g;
    total=total+charge;
    printf("       722              47                   $ %f \n", ++i, charge_counter(q));
    total=total+charge;
    printf("Total: %d               3740                 $ %d \n", i, total);
    
    return 0;
    }
    
    float charge_counter(int *q)
    {float charge;
    int y;
    y = *q;
            if (y <= 300)
            {charge = .09 * y;}
            else
                    if (y > 300 &&  y <= 600)
               { (charge = 27 + (y - 300) * .08);}
               else
               { if (y > 600 && y <= 1000)
                       { (charge = 51 + (y - 600) * .06);}
                       else
                       {(charge = 75 + (y - 1000) * .05);}
            }
    return charge;
    Now, what the hell am I doing wrong? I'm sure it has something to do with my pointer poerator... or something...

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Do you have a function definition for void first_prn() ? I didn't see one.

  3. #3
    Freez3L
    Guest
    damn. I do have one, but it left it out. I'm at college and we use a compiler on a remote server (i.e. we write the source in the client window)

    it's merely a line of text and there are no variables in it. insignificant.
    Thank you for noticing though!!!

  4. #4
    Freez3L
    Guest
    the ++i was supposed to increment a counter to tell the number of total customers.
    /* Programming for school...damn i hate those rules...*/

    Anyway, the deal with not using & is that I have to "Demonstrate how pointers can be used to solve the problem."


    Hell, I'd write the whole damn thing in one function without pointers if I could.

  5. #5
    Freez3L
    Guest
    oh BTW, ,the reason for the repetition of the pointer was to reassign it... i.e. assign pointer q to a new variable every time I call the function. /* Damn programming class...*/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-27-2009, 02:33 PM
  2. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  3. assignment makes pointer from integer without a cast
    By lithium in forum C Programming
    Replies: 1
    Last Post: 04-02-2003, 11:37 PM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 11:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM

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