# Ch4_2 - cout<<"Enter liters of gasoline for car...

This preview shows page 1. Sign up to view the full content.

#include <iostream.h> #include <conio.h> /************************************************** Name: Hung Truong Program: Chapter 4_2: Miles per gallon of 2 car. Which is better? Instructor: Mr. Barkeshli Purpose: Input: Number of liters of gasoline, number of miles travelled Output: Miles per gallon each car, which is better. **************************************************/\ const double GAL=0.264179; bool t=true; double l1,l2,m1,m2; char c; double mpg(double gal, double mil); // Calculate the miles per gallon main() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); cout<<"Enter liters of gasoline for car 1: ";cin>>l1;l1=l1*GAL; cout<<"Enter miles travelled for car 1: ";cin>>m1;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<<"Enter liters of gasoline for car 2: ";cin>>l2;l2=l2*GAL; cout<<"Enter miles travelled for car 2: ";cin>>m2; /***************************************************/ cout<<"Miles per gallon car 1 : "<<mpg(l1,m1)<<endl; cout<<"Miles per gallon car 2 : "<<mpg(l2,m2)<<endl; if (mpg(l1,m1)<mpg(l2,m2)) cout<<"Car 2 got best fuel efficiency"<<endl; else cout<<"Car 1 got best fuel efficiency"<<endl; /***************************************************/ while (t==true) { cout<<"You want to do it again(Y/N)? ";cin>>c; t=(c=='Y')|(c=='y'); } } double mpg(double gal, double mil) { double temp; temp=mil/gal; return temp; }...
View Full Document

## This note was uploaded on 03/20/2011 for the course CS 2 taught by Professor Barkeshli during the Spring '11 term at Pasadena City College.

Ask a homework question - tutors are online