{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
#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); while (t==true) { cout<<"Enter liters of gasoline for car 1: ";cin>>l1;l1=l1*GAL; cout<<"Enter miles travelled for car 1: ";cin>>m1;
Background image of page 1
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; /***************************************************/ / 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

{[ snackBarMessage ]}

Ask a homework question - tutors are online