7
Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung (COM612102) ALGORITMA DAN PEMROGRAMAN TUMING 4 ALDO ADIGIA PRADIPTA | 1517051158 email: [email protected] PROGRAM STUDI S1 ILMU KOMPUTER JURUSAN ILMU KOMPUTER Universitas Lampung, Jln. Prof. Dr. Sumantri Brojonegoro No. 1 35145, Indonesia Question Requires: variables, data types, and numerical operators basic input/output logic (if statements, switch statements) Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water, Sprite, ... , Whatever). Then allow the user to choose a beverage by entering a number 1-5. Output which beverage they chose. If you program uses if statements instead of a switch statement, modify it to use a switch statement. If instead your program uses a switch statement, modify it to use if/else-if statements. ★★ Modify the program so that if the user enters a choice other than 1-5 then it will output "Error. choice was not valid, here is your money back.

Com612102 1517051158 Aldo Adigia Pradipta

Embed Size (px)

DESCRIPTION

Tugas Mingguan C++

Citation preview

Page 1: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

(COM612102) ALGORITMA DAN PEMROGRAMAN

TUMING 4

ALDO ADIGIA PRADIPTA | 1517051158

email: [email protected]

PROGRAM STUDI S1 ILMU KOMPUTER

JURUSAN ILMU KOMPUTER

Universitas Lampung, Jln. Prof. Dr. Sumantri Brojonegoro No. 1 35145, Indonesia

Question

Requires:

variables, data types, and numerical operators

basic input/output

logic (if statements, switch statements)

Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water,

Sprite, ... , Whatever).

Then allow the user to choose a beverage by entering a number 1-5.

Output which beverage they chose.

★ If you program uses if statements instead of a switch statement, modify it to use a switch

statement.

If instead your program uses a switch statement, modify it to use if/else-if statements.

★★ Modify the program so that if the user enters a choice other than 1-5 then it will output "Error.

choice was not valid, here is your money back.

Page 2: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

Source Code C++

/*

* Hello.cpp

*

* Created on: 20 Okt 2015

* Author: Aldo Adigia Pradipta | 1517051158

*/

#include <iostream>

using namespace std;

int main()

{

int choice;

double P, Tot;

string choice2;

cout << "++++++++++Minuman Favorit Masa Kini, Silahkan Pilih

:)++++++++++\n\n";

cout << "MENU MINUMAN :\n";

cout << "1. Coca Cola \n";

cout << "2. Sprite \n";

cout << "3. Big Cola \n";

cout << "4. Bear Brand \n";

cout << "5. Fanta \n";

cout << "6. Kiranti \n";

cout << "7. Milo \n";

cout << "8. L-Men \n";

disini:

cout << "\nPilih 1-8 Untuk Membeli Minuman Favorit Anda = ";

cin >> choice;

{

if(choice==1){cout<<"\nCoca Cola\n";

cout<<"Harga : Rp5.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<".000,00\n";

cout<<"\n";}

else

if(choice==2){cout<<"\nSprite\n";

cout<<"Harga : Rp5.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";}

else

if(choice==3){cout<<"\nBig Cola\n";

cout<<"Harga : Rp5.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";}

else

if(choice==4){cout<<"\nBear Brand\n";

cout<<"Harga : Rp8.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*8;

cout<<"Total = Rp "<<Tot<<"000,00\n";

Page 3: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

cout<<"\n";}

else

if(choice==5){cout<<"\nFanta\n";

cout<<"Harga : Rp5.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";}

else

if(choice==6){cout<<"\nKiranti\n";

cout<<"Harga : Rp10.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*10;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";}

else

if(choice==7){cout<<"\nMilo\n";

cout<<"Harga : Rp3.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*3;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";}

else

if(choice==8){cout<<"\nL-Men\n";

cout<<"Harga : Rp10.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*10;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";}

else{

cout << "\nMaaf, Kami Hanya Menyediakan 8 Minuman, Silahkan Ambil

Kembali Uang Anda atau\n";

goto disini;}

}

cout << "=============Letakkan Uang Di Tempat Yang Sudah

Tersedia=============\n\n";

cout << "============================Terima

Kasih=============================\n";

cout << "=============Selamat Menikmati dan Selamat Belanja

Kembali=========== :v\n\n\n\n";

return 0;

}

Page 4: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

Screenshoot Output Program

Page 5: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

Source Code C+

/*

* Hello.cpp

*

* Created on: 20 Okt 2015

* Author: Aldo Adigia Pradipta | 1517051158

*/

#include<iostream>

using namespace std;

int main()

{

int Pilihan;

double P,np,Tot,etj,aj;

cout<<"_______________________________________________\n";

cout<<"+++++++++++Minuman Favorit Masa Kini+++++++++++\n";

cout<<"-----------------------------------------------\n\n";

cout<<"MENU MINUMAN :\n";

cout<<"1.Coca Cola\n";

cout<<"2.Sprite\n";

cout<<"3.Big Cola\n";

cout<<"4.Bear Brand\n";

cout<<"5.Kiranti\n";

cout<<"-------------------\n";

disini:

cout<<"Silahkan Pilih : ";cin>>Pilihan;

cout<<"-------------------\n";

switch(Pilihan)

{

case 1:

cout<<"Coca Cola\n";

cout<<"Harga : Rp5.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";

cout<<"Terima Kasih dan Silahkan Menikmati\n";

cout<<"_______________________________________________\n";

goto disini;

break;

case 2:

cout<<"Sprite\n";

cout<<"Harga : Rp5.000\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";

cout<<"Terima Kasih dan Silahkan Menikmati\n";

cout<<"_______________________________________________\n";

goto disini;

break;

case 3:

cout<<"Big Cola\n";

cout<<"Harga : Rp5.000,00\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*5;

cout<<"Total = Rp "<<Tot<<"000,00\n";

Page 6: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

cout<<"\n";

cout<<"Terima Kasih dan Silahkan Menikmati\n";

cout<<"_______________________________________________\n";

goto disini;

break;

case 4:

cout<<"Bear Brand\n";

cout<<"Harga : Rp8.000\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*8;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";

cout<<"Terima Kasih dan Silahkan Menikmati\n";

cout<<"_______________________________________________\n";

goto disini;

break;

case 5:

cout<<"Kiranti\n";

cout<<"Harga : Rp10.000\n";

cout<<"Jumlah : ";cin>>P;

cout<<"--------------\n";

Tot=P*10;

cout<<"Total = Rp "<<Tot<<"000,00\n";

cout<<"\n";

cout<<"Terima Kasih dan Silahkan Menikmati\n";

cout<<"_______________________________________________\n";

goto disini;

break;

default :

cout<<"Hanya Bisa Memilih Minuman Yang Ada atau Ambil

Kembali Uang Anda.(Pilih1-5)!!\n\n";

goto disini;

break;

}

return 0;

}

Page 7: Com612102 1517051158 Aldo Adigia Pradipta

Aldo Adigia Pradipta, Ilmu Komputer, Universitas Lampung

Screenshoot Output Program