1. ## C coding class

So I'm taking a Intro to C coding class, and my teacher want me to do a simple code for out hw.

Code:
```#include <stdio.h>

int main(void)
{
double orLbs;
int enerNum, yoNum;
double orPrice, ePrice, yPrice;
double tax = 0.065;

orPrice = orLbs*0.95;
ePrice = enerNum*1.5;
yPrice = yoNum*0.75;

printf("Lbs of Oranges? ");
scanf("%lf", &orLbs);
printf("Number of energy drinks? ");
scanf("%li", &enerNum);

printf("Item		Cost		Tax\n");
printf("Orange		%.2f\n", orPrice);
printf("Energy Drinks	%.2f		%.2f\n", ePrice, ePrice*tax);
}```
the problem is that it's not calculating the price correctly, what is wrong with the code?

- - - Updated - - -

btw, Im righting the code and running it on a unix server

2. Originally Posted by w4ssup
So I'm taking a Intro to C coding class, and my teacher want me to do a simple code for out hw.

Code:
```#include <stdio.h>

int main(void)
{
double orLbs;
int enerNum, yoNum;
double orPrice, ePrice, yPrice;
double tax = 0.065;

orPrice = orLbs*0.95;
ePrice = enerNum*1.5;
yPrice = yoNum*0.75;

printf("Lbs of Oranges? ");
scanf("%lf", &orLbs);
printf("Number of energy drinks? ");
scanf("%li", &enerNum);

printf("Item		Cost		Tax\n");
printf("Orange		%.2f\n", orPrice);
printf("Energy Drinks	%.2f		%.2f\n", ePrice, ePrice*tax);
}```
the problem is that it's not calculating the price correctly, what is wrong with the code?

- - - Updated - - -

btw, Im righting the code and running it on a unix server
Okay first of you should initialize all your variables, it's a bad habit and can cause errors. Second you need to run the code that actually does the math after you get the values! Good luck on learning C.
Code:
```#include <stdio.h>
int main(void)
{
double orLbs = 0;
int enerNum = 0, yoNum = 0;
double orPrice = 0, ePrice = 0, yPrice = 0;
double tax = 0.065;

printf("Lbs of Oranges? ");
scanf("%lf", &orLbs);
printf("Number of energy drinks? ");
scanf("%li", &enerNum);

orPrice = orLbs*0.95;
ePrice = enerNum*1.5;
yPrice = yoNum*0.75;

printf("Item		Cost		Tax\n");
printf("Orange		%.2f\n", orPrice);
printf("Energy Drinks	%.2f		%.2f\n", ePrice, ePrice*tax);
}```

3. ## The Following User Says Thank You to Ponzi For This Useful Post:

w4ssup (09-25-2015)

4. Originally Posted by Ponzi<3
Okay first of you should initialize all your variables, it's a bad habit and can cause errors. Second you need to run the code that actually does the math after you get the values! Good luck on learning C.
Code:
```#include <stdio.h>
int main(void)
{
double orLbs = 0;
int enerNum = 0, yoNum = 0;
double orPrice = 0, ePrice = 0, yPrice = 0;
double tax = 0.065;

printf("Lbs of Oranges? ");
scanf("%lf", &orLbs);
printf("Number of energy drinks? ");
scanf("%li", &enerNum);

orPrice = orLbs*0.95;
ePrice = enerNum*1.5;
yPrice = yoNum*0.75;

printf("Item		Cost		Tax\n");
printf("Orange		%.2f\n", orPrice);
printf("Energy Drinks	%.2f		%.2f\n", ePrice, ePrice*tax);
}```
I think you meant shouldn't, but thanks it works now

5. Research on how to use a debugger; It will help you find errors as they happen.

6. ## The Following User Says Thank You to Dave84311 For This Useful Post:

koshinator (09-25-2015)

7. Originally Posted by Dave84311
Research on how to use a debugger; It will help you find errors as they happen.
Unix doesnt give me an error, and I tried googling "C code tester" or "c code analyzer" and they didnt work out so well. I use to have vs2010, but i deleted it lol