# What's wrong with my calculator?

• 09-08-2010
andrewmin
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?
• 09-08-2010
andrewmin
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.
• 09-08-2010
rags_to_riches
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.
• 09-08-2010
andrewmin
Quote:

Originally Posted by rags_to_riches
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!