You are on page 1of 5

NAME : MOHD FAKHRUL AIZAM BIN MOHD NORMAN

NO MATRIX: BS01202007
PROGRAM : BKEG, MELAKA 6

Exercise 4.3
1.
SOURCE CODE
#include <iostream>

using namespace std;

int main()

int hour;

float total;

char code;

cout << "Enter your vehicle code (C)ar/(L)orry/(B)us:" ;

cin >> code ;

if (code == 'C' || code == 'c' || code =='B'|| code=='b' || code=='L' || code=='l')

cout << "Enter your parking duration (in hour): ";

cin >> hour;

if(code == 'C' || code == 'c') //Jika kenderaan adalah kereta

if(hour <= 3)

total = 1.00;

else

total = 1.00; // Bayaran 3 jam pertama 1+6


total = total + ((hour - 3) * 1.50); // Bayaran jam berikut

else if (code == 'L' || code == 'l') //Jika kenderaan adalah lori

if(hour <= 3)

total = 1.50;

else

total = 1.50; // Bayaran 3 jam pertama

total = total + ((hour - 3) * 2.50); // Bayaran jam berikut

else if (code == 'B' || code == 'b') //Jika kenderaan adalah bas

if(hour <= 3)

total = 2.00;

else

total = 2.00; // Bayaran 3 jam pertama

total = total + ((hour - 3) * 3.50); // Bayaran jam berikut

cout << "Your parking charge is RM" <<total;

}
else //selain dari kod di atas... keluarkan error mesej

cout << "Invalid code!";

return 0;

OUTPUT
2.

SOURCE CODE
#include <iostream>

using namespace std;

int main()

int unit, disc;

const float harga_seunit= 20.00;

float total_cost;

cout << "\t\t\t\t\tGlamour Book Store\n\n";

cout << "Enter number of unit sold : ";

cin >> unit;

if (unit >= 0)// Jika input sah lakukan berikut

total_cost = harga_seunit * unit;

if (unit >= 10 && unit <=19)

total_cost = total_cost - (total_cost * 20/100);

else if (unit >= 20 && unit <=49)

total_cost = total_cost - (total_cost * 30/100);

else if (unit >= 50 && unit <=99)

total_cost = total_cost - (total_cost * 40/100);

} else if (unit >=100)

{
total_cost = total_cost - (total_cost * 50/100);

cout << "Total cost of the purchase is RM" << total_cost;

else // Jika input tidak sah keluar error mesej

cout << "Input not valid";

return 0;

OUTPUT

You might also like