Thread: Help with program homework!!!

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Exclamation Help with program homework!!!

    I have to write a program that determines the miles per gallon for
    3 tanks of gasoline. The program prompts you to enter the number of gallons used and number of miles driven for each of the 3 tankfuls of gas. The program will then calculate and display the miles per gallon obtained for each tankful. I can't figure out how to write the statement to calculate this. Below is what I have. If anyone can help, or give me some idea on where I am wrong, i would appreciate it.
    Code:
    /* Variable Declarations */
        
        int x, result, miles_per_gallon;
        float gallons_used, miles_driven;
    
    /* Greeting*/
    
        printf("Welcome to the Acme Mileage Calculator Program\n\n");
    
        printf ("Enter the number of gallons used:");
        scanf ("%.1f",&gallons_used);
    
        printf("Enter the number of miles driven:");
        scanf("%.1f",&miles_driven);
    
        for (x = galons_used / miles_driven;)
    
        result = x;
    
        printf("Miles per gallon for this tank is %i\N",x,result);
    [edited for code tags by ygfperson]
    I know the result is wrong....does anyone have an example similar that uses division?
    Thank you.

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Have you even tried to compile? It'll point you to all the errors and you should be able to debug it.

    >> for (x = galons_used / miles_driven
    This is an infinite loop. You misspelled galons_used. Variable x is type int, therefore you results will be truncated (you'll lose decimal values).

    Having both variables x and result is redundant.

    >> printf("Miles per gallon for this tank is %i\N",x,result);
    You printed out 1 parameter here but passed in 2.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2
    I am only allowed to use 1 variable and 2 to 3 floats. How do I create the formula only using one variable? I picked x to = the miles per gallon and tried to work backwards...am I way off? Thank you for your help

  4. #4
    Your for loop is way off...

    for(int x=0;x<100;x++)
    {

    cout<<x<<endl; //Outputting x
    }

    That's just the format of the for loop... not the way you have it.

    Also, you want to change the math to

    (miles_driven/gallons_used)
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Fix the obvious errors first. Your loop tells me you don't even know the basics. Why not start there first?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM