-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPG Program
More file actions
52 lines (44 loc) · 1.03 KB
/
MPG Program
File metadata and controls
52 lines (44 loc) · 1.03 KB
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
// MPG
/* At the beginning of a car journey the driver ensures that the car's
fuel tank is full and records the odometer reading. After the journey he records
the new reading and how much fuel it took to refill the tank. Develop a
program which will calculate the fuel consumption.
*/
#include "stdafx.h"
#include <iostream>
using namespace std;
//methods
void input();
void calculations();
void output();
//global variables
double consumption = 0.0;
int distance_travelled;
int _tmain(int argc, _TCHAR* argv[])
{
input();
calculations();
return 0;
}
void input()
{
int first, second;
cout << "What was your first reading : ";
cin >> first;
cout << "What was your second reading : ";
cin >> second;
distance_travelled = second - first;
}
void calculations()
{
double refill, refill_litres;
cout << "How many litres have you topped up : ";
cin >> refill_litres;
refill = refill_litres * 0.219969;
consumption = distance_travelled/refill;
output();
}
void output()
{
cout << "Your MPG was : " << consumption << endl;
}