-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_6.cpp
56 lines (45 loc) · 1.3 KB
/
3_6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
const double KilometerPerMile = 1.6093;
const double LiterPerGallon = 3.7854;
int main()
{
using namespace std;
double gallons = 0;
double miles = 0;
cout << "Please enter the distance (in miles): ";
while(!(cin >> miles) || (0 >= miles))
{
cout << "Error! Please enter a positive number: ";
cin.clear();
cin.sync();
}
cout << "Please enter the fuel (in gallons): ";
while(!(cin >> gallons) || (0 >= gallons))
{
cout << "Error! Please enter a positive number: ";
cin.clear();
cin.sync();
}
double distancePerGallon = miles / gallons;
cout << "The distance per gallon is " << distancePerGallon << " miles." << endl;
double liters = 0;
double kilometers = 0;
cout << "Please enter the distance (in kilometers): ";
while(!(cin >> kilometers) || (0 >= kilometers))
{
cout << "Error! Please enter a positive number: ";
cin.clear();
cin.sync();
}
cout << "Please enter the fuel (in liters): ";
while(!(cin >> liters) || (0 >= liters))
{
cout << "Error! Please enter a positive number: ";
cin.clear();
cin.sync();
}
double fuelConsumption = liters * 100 / kilometers;
cout << "The fuel consumption is " << fuelConsumption << " liter every 100 kilometers." << endl;
// system("pause");
return 0;
}