Thread: what's the problem here?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    11

    what's the problem here?

    I won't bore you with details, but this program I've been working on crashes every time, right after I enter the value for the first variable and I don't have a clue why. Any ideas?

    -----

    /* This program calculates and displays a car's mpg for an indefinite number of tankfulls, then calculates and displays the average mpg. */

    #include <stdio.h>

    int main()
    {
    float gal, mil, mpg;
    int sum = 0, count = 0;

    printf( "Enter the gallons used (-1 to end): ");
    scanf( "%f", gal );

    while ( x != -1 )
    {
    printf( "Enter the miles driven: " );
    scanf( "%f", mil );
    mpg = mil / x;
    printf( "The mpg for this tank was %f", mpg);
    sum += mpg;
    ++count;
    printf( "Enter the gallons used (-1 to end): ");
    scanf( "%f", gal );
    }

    printf( "The overall average mpg was %f", sum / count );

    return 0;

    }

    -----------

    Thanks.

    Ash

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    scanf() takes the address of the variable so you want something like -

    scanf( "%f", &mil );

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    11
    <smacks self on head>

    duh!

    Thanks, zen.

    Ash

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM