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);
}