What's wrong with my calculator?

This is a discussion on What's wrong with my calculator? within the C Programming forums, part of the General Programming Boards category; I made a calculator for an economics class that is supposed to decide how much to charge a buyer based ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    What's wrong with my calculator?

    I made a calculator for an economics class that is supposed to decide how much to charge a buyer based on how much you want to profit. For some reason, though, GCC is having issues. In the end, the answer (with a 100 profit target, 300 maintenance, 2/cost of a meatie and veggie burger, and demand of 250 for meatie and 250 for veggie) was -0.027938 dollars. Here's the code:

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(void) {
    
    /* Variables */
    
    float profit;
    float overheadfactories;
    float overheadmeatie;
    float overheadveggie;
    float demandmeatie;
    float demandveggie;
    float buyercost;
    
    /* Input */
    
    printf("How much of a profit do you want?\n");
    scanf("%f",&profit);
    
    //Debugging printf("%f\n",&profit);
    
    printf("How much is your total factory maintenance?\n");
    scanf("%f", &overheadfactories);
    
    printf("How much does it cost you to produce a Meatie burger?\n");
    scanf("%f", &overheadmeatie);
    
    printf("How much does it cost you to produce a Veggie burger?\n");
    scanf("%f", &overheadveggie);
    
    printf("How many Meatie burgers does the buyer want?\n");
    scanf("%f", &demandmeatie);
    
    printf("How many Veggie burgers does the buyer want?\n");
    scanf("%f", &demandveggie);
    
    /* Math */
    
    buyercost = (overheadfactories + (overheadmeatie * demandmeatie) + (overheadveggie * demandveggie)) + (profit / 0.85);
    
    /* Output */
    
    printf("The buyer should send you %f dollars\n", &buyercost);
    
    }
    What's wrong with it?
    Last edited by andrewmin; 09-08-2010 at 01:10 PM.

  2. #2
    Registered User
    Join Date
    Sep 2010
    Posts
    3
    Also, if I comment out the rest and only use the following:

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(void) {
    
    float profit;
    float overheadfactories;
    float overheadmeatie;
    float overheadveggie;
    float demandmeatie;
    float demandveggie;
    float producemeatie;
    float produceveggie;
    float buyercost;
    
    printf("How much of a profit do you want?\n");
    scanf("%f",&profit);
    printf("%f\n",&profit);
    }
    It gives me all sorts of numbers for the output (for the input 123): -0.111523, -1.087090... it changes every time I run it. So does codepad.org's compiler.
    Last edited by andrewmin; 09-08-2010 at 01:14 PM.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Code:
    printf("The buyer should send you %f dollars\n", &buyercost);
    Lose the & on the buyercost. That's printing the float format of the address of the buyercost variable.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    3
    Quote Originally Posted by rags_to_riches View Post
    Code:
    printf("The buyer should send you %f dollars\n", &buyercost);
    Lose the & on the buyercost. That's printing the float format of the address of the buyercost variable.
    That fixed it. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-16-2010, 03:29 PM
  2. No decent linux calculator?!??
    By MK27 in forum Tech Board
    Replies: 22
    Last Post: 12-16-2009, 10:31 AM
  3. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 04:50 PM
  4. What am I doing wrong ?
    By scottjge in forum C Programming
    Replies: 6
    Last Post: 10-01-2009, 12:55 PM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM

Tags for this Thread


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