Thread: Need help please :) Newbie trying to learn

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    33

    Smile Need help please :) Newbie trying to learn

    This is how I need the output of the program to look:

    Welcome to My Mileage calculator

    This program will calculate the miles per gallon for you for three tanks of gas after you have entered the gallons used and the miles driven

    Enter the number of gallons used for tank #1: 12.8
    Enter the number of miles driven: 287.1
    ***The miles per gallon for this tank is 22.4

    Enter the number of gallons used for tank #2: 10.3
    Enter the number of miles driven: 200.2
    ***The miles per gallon for this tank is 19.4

    Enter the number of gallons used for tank #3: 5.2
    Enter the number of miles driven 120.9
    ***The miles per gallon for this tank is 23.3

    Your overall average miles per gallon for three tanks is 21.5

    Thank you for using My mileage calculator program

    This is what I have written so far. My question is how do I get it to calculate overall average miles per gallon for the all three tanks and also how do I get it to ask for tank 1, tank 2 , tank 3? Mine just says tank 1 on each one.

    Code:
    #include <stdio.h>
    
    void main (void)
    {
    	/*Variable Delclarations*/
    	/*----------------------*/
    	 int   quotient, gallused, milesdriven;
    	 float gallons_used;
    	 float miles_driven;
    	 float avg;
    
    	/*Display program info*/
       /*--------------------*/
    
    
    	 printf ("\nWelcome to Colleen's mileage calculator.\n");
    	 printf ("\nThis program will calculate the miles per gallon for you for\n");
    	 printf ("three tanks of gas after you have entered the gallons used and\n");
    	 printf ("miles driven.\n");
    
    	 /*Prompt user for information*/
    	 /*------------------*/
    
    	 for (gallused = 1; gallused <= 3; ++ gallused )
    	{
    	 printf ("\nEnter the number of gallons used for tank #1: ");
    	 scanf  ("%f", &gallons_used);
        fflush (stdin);
    
    
    	 printf ("Enter the number of miles driven: ");
    	 scanf  ("%f", &miles_driven);
    	 fflush (stdin);
    
    	 gallons_used = miles_driven / gallons_used;
    
    	 printf ("***The miles per gallon used for this tank is %.1f \n",gallons_used);
    	 fflush (stdin);
    
    	 } // end of loop
    
    	 gallons_used = avg / gallons_used;
    
    	 printf ("\nYour overall average miles per gallon for three tanks is %.1f \n", avg);
    	 fflush (stdin);
    
    
    
    	/*Display Results*/
    	/*---------------*/
    
    
    	 printf ("\nThanks for using Colleen's Mileage calculator program!\n");
    
    
    } //end main
    Last edited by paulntysmom; 03-07-2006 at 01:14 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do you ever try to learn too much?
    By Stonehambey in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 06-17-2008, 07:55 AM
  2. Can you actually learn c++ in 21 days?
    By Raeliean in forum C++ Programming
    Replies: 14
    Last Post: 07-27-2005, 03:41 PM
  3. You have to learn C in order to learn C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 07-16-2004, 10:33 AM
  4. Novice trying to learn C++
    By dead in forum C++ Programming
    Replies: 10
    Last Post: 12-01-2003, 09:25 PM
  5. Trying to learn guitar
    By Ben_Robotics in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-10-2003, 03:15 AM