-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (52 loc) · 1.79 KB
/
main.cpp
File metadata and controls
77 lines (52 loc) · 1.79 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Name:
//class:
//Description: This program ask user for distances in kilometer and gasoline used in litres, and it converts given inouts into miles and gallon. Then it output result in MPG(miles per gallon). It show outputs in floating point
//Pre-condition: input must be an integer
//post-condition: none
#include <iostream>
using namespace std;
#include <cmath>
#include <iomanip>
int main()
{
//Description: Kilometer1, kilometer2, and litres are to be input from user. Gallon, distance, distance, miles, and MPG are to be calculated values.
int kilometer1;
int kilometer2;
int litres;
double gallon;
double distance;
double miles;;
double MPG;
//It format to 2 decimals
cout<< fixed << showpoint <<setprecision(2);
//ask user for kilometer inputs
cout<<" Enter distance in kilonmeter car travelled: ";
//assign input as kilometer1
cin>>kilometer1;
//ask user for kilometer inputs
cout<<" Enter the number of kilometer car has travelled: ";
//assign input as kilometer1
cin>> kilometer2;
if (kilometer2<kilometer1)
cout<<"Enter number of kilometer travelled by car!!!: ";
cin>>kilometer2;
else
cin>>kilometer2;
//calculate distance travelled by car
distance=(kilometer2-kilometer1);
//output distance travelled by a car
cout<<" Distance travelled by a car: "<<distance<<endl;
//convert distance into miles
miles=(distance/1.60934);
cout<<"Distance travlled by a car in miles: "<<miles<<endl;
cout<<" Enter the number of gasoline used in litres: ";
cin >>litres;
//convert litres into gallon
gallon=litres/3.78541;
cout<<" Gallon used while travelling: "<<gallon<<endl;
//calculate MPG(miles per gallon)
MPG=(miles/gallon);
//output required calculation of MPG
cout<<" Required MPG: "<<MPG<<endl;
return 0;
}