-
Notifications
You must be signed in to change notification settings - Fork 0
/
02.21.CostOfDriving.cpp
62 lines (50 loc) · 2.16 KB
/
02.21.CostOfDriving.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
57
58
59
60
61
62
#include <iostream>
/*
=====================================================================================
02.21. Cost Of Driving
by : #bayuyudhasaputra
lang : IDN (Bahasa Indonesia)
-------------------------------------------------------------------------------------
Masalah :
Write a program that prompts the user to enter the distance to drive, the
fuel efficiency of the car in miles per gallon, and the price per gallon,
and displays the cost of the trip.
======================================================================================
*/
int main()
{
std::cout << std::endl
<< " ======================================================================== "
<< std::endl;
// 1. Input jarak tempuh
std::cout << " Input jarak tempuh dalam satuan mil (Misal, 900.5) : ";
double jarakTempuh;
std::cin >> jarakTempuh;
std::cout << std::endl;
// 2. Input efisiensi bahan bakar
std::cout << " Input efisiensi bahan bakar dalam satuan mil per galon (Misal. 25.5) : ";
double efisiensi;
std::cin >> efisiensi;
std::cout << std::endl;
// 3. Input harga bahan bakar per galon
std::cout << " Input harga bahan bakar per galon (Misal. 3.55) : ";
double hargaBahanBakar;
std::cin >> hargaBahanBakar;
std::cout << std::endl;
// 4. Hitung biaya total
double biayaTotal;
biayaTotal = (jarakTempuh / efisiensi) * hargaBahanBakar;
// 5. Tampilkan biaya total
std::cout << " ------------------------------------------------------------------------ "
<< std::endl
<< " Biaya total untuk membeli bahan bakar adalah USD."
<< biayaTotal
<< std::endl
<< " ======================================================================== ";
return 0;
}
/*
Liang. 2014. Introduction to Programming with C++ 3rd Edition.
London : Pearson Education.
https://www.pearson.com/en-us/subject-catalog/p/Liang-Companion-Website-for-Introduction-to-Programming-with-C-Access-to-Videonotes-3rd-Edition/P200000003422/978013338026
*/