VB icon

Calculate fuel efficiency

Email
Submitted on: 1/1/2015 5:39:00 AM
By: Wilton Marranzini (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: C++ (general)
Views: 3509
 
     Program calculates the fule effiency of the car on the trip in miles/gallon and the cost for gasoline at the end of the trip. It teaches begginer programmers functions and calculations.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Calculate fuel efficiency
// Description:Program calculates the fule effiency of the car on the trip in miles/gallon and the cost for gasoline at the end of the trip. It teaches begginer programmers functions and calculations.
// By: Wilton Marranzini (from psc cd)
//
// Inputs:number of miles travel. the number of gallons purchased. and the price per gallon.
//
// Returns:The fuel efficiency, miles per number of gallons, Gallons used on the trip, and The cost of the trip
//**************************************

/*
Author: Wilton Marranzini
Objective: Program calculates the fule effiency of the car on the trip in
miles/gallon and the cost for gasoline at the end of the trip.
*/
#include <iostream.h> //including lib.
#include <math.h> //including lib.
#include <cstring.h> //including lib.
 //Prototypes functions
void description();//Description cout fuction.
float full_efficiency(int miles, int gallons);//efficiency function.
float cost(float price, int gallons); //Cost function.
int main()//Main Function
{ string gas_station;//String for gas station name.
int num_miles; // Variable for number of miles
int num_gallons;//Variable for number of gallons.
float price_per_gallons;//Variable for price per gallons.
float efficiency; //variable for efficiency.
float cos; //variable for cost
int a; //keeps screen function
description(); //Discription function
cout<< "Enter gas station name\n";
getline(cin, gas_station); //Getting gas station title
cout<< "Name of gas station Is " << gas_station <<".\n";
cout<<endl;
cout<< "Enter the numbers of miles travel.\n";
cin>>num_miles;//storing numbers of miles
cout<< "Enter the number of gallons of gasoline purchased.\n";
cin>>num_gallons;//storing number of gallons
cout<< "Enter the Price per gallons.\n";
cin>>price_per_gallons;//storing price per gallons
efficiency = full_efficiency(num_miles,num_gallons);//calling function.
cos =cost(price_per_gallons,num_gallons);//calling function.
cout<<"The efficiency is "<<efficiency<<" for "
<<num_miles<<" miles per number of "<<num_gallons<<" gallons\n";
cout<<"Gallons used on the trip is "<<num_gallons<<" The cost of the trip "
<<"is "<<"$"<< cos <<endl;
cin>>a; //keeps screen open
return 0;//returning value
}
void description()
{
	cout<< "Program calculates the fule effiency of the car on the trip\n"
	 << "in miles/gallon and the cost for gasoline at the end of the\n"
<< "trip.\n";
}
float full_efficiency(int miles, int gallons)
{
	float efficien; //efficiency variable
	efficien = miles/gallons;
	return (efficien);//returning value
}
float cost(float price, int gallons)
{
	float charge;//charge variable
charge = price*gallons;
return (charge); //returning value
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.