Thread: C coding class

Results 1 to 5 of 5
  1. #1
    w4ssup's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    1,500
    Reputation
    10
    Thanks
    385

    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. #2
    Ponzi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    Elysium
    Posts
    234
    Reputation
    82
    Thanks
    1,682
    My Mood
    Buzzed
    Quote Originally Posted by w4ssup View Post
    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);
    }
    Last edited by Ponzi; 09-25-2015 at 08:38 PM.

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

    w4ssup (09-25-2015)

  4. #3
    w4ssup's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    1,500
    Reputation
    10
    Thanks
    385
    Quote Originally Posted by Ponzi<3 View Post
    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. #4
    Dave84311's Avatar
    Join Date
    Dec 2005
    Gender
    male
    Location
    The Wild Wild West
    Posts
    29,870
    Reputation
    4042
    Thanks
    37,712
    My Mood
    Devilish
    Research on how to use a debugger; It will help you find errors as they happen.





    THE EYE OF AN ADMINISTRATOR IS UPON YOU. ANY WRONG YOU DO IM GONNA SEE, WHEN YOU'RE ON MPGH, LOOK BEHIND YOU, 'CAUSE THATS WHERE IM GONNA BE


    "First they ignore you. Then they laugh at you. Then they fight you. Then you lose.” - Dave84311

    HAD VIRTUAL DETOX

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

    koshinator (09-25-2015)

  7. #5
    w4ssup's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    1,500
    Reputation
    10
    Thanks
    385
    Quote Originally Posted by Dave84311 View Post
    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

Similar Threads

  1. [Help] Extract code/class files from java exe
    By benny87 in forum General Game Hacking
    Replies: 1
    Last Post: 10-26-2012, 05:07 PM
  2. [Release] BFP4F class codes
    By micJimmyJim in forum Battlefield Play4Free Hacks
    Replies: 20
    Last Post: 02-02-2012, 04:32 AM
  3. [Release] More Secondary Weapon Perk Code for Jorndel's Class Hack Tool
    By lzpsmith in forum Call of Duty 8 - Modern Warfare 3 (MW3) Hacks & Cheats
    Replies: 3
    Last Post: 01-14-2012, 04:42 PM
  4. [Discussion] New AVA coding class and other games
    By sam22 in forum Alliance of Valiant Arms (AVA) Discussions
    Replies: 5
    Last Post: 12-21-2010, 07:33 AM
  5. pacman java -class code
    By Gourav2122 in forum Java
    Replies: 6
    Last Post: 10-26-2010, 09:05 AM