next up previous
Next: Example 3 Up: Newline Previous: Newline

Example 2








/* This program should be saved as prog2.cpp
This program will convert the given gallons (integer)
to liters (real)
The user should be able to enter the number of gallons
through the keyboard and the compute should letters the
output on the screen 1 gallon=3.7854 liters */

#include <iostream.h>

main( )
{
int gallons;
float liters;
cout << "Enter a whole number of gallons: ";
cin >> gallons; // this inputs from the user
liters=3.7854*gallons; // convert to liters
cout << "Liters =" << liters << "$\backslash$ n";
return 0;
}



Yousef Haik
2/23/1998