You are on page 1of 4

(COM612102) ALGORITMA DAN PEMROGRAMAN

TUMING 4
Novella Daria Utami | 1517051135
email: novelladariautami@gmail.com

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."

Novella Daria Utami, Ilmu Komputer, Universitas Lampung

Source Code C++

/*
* Hello.cpp
*
* Created on: 20 okt 2015
*
Author: Novella Daria Utami | 1517051135
*/
#include <iostream>
using namespace std;
main(){
int drink;
cout<<"\t\t\t===Hello Welcome Customer==="<<endl;
cout<<"Please Select your Drink..."<<endl;
cout<<"1. CocaCola"<<endl;
cout<<"2. Mineral Water"<<endl;
cout<<"3. Root Beer"<<endl;
cout<<"4. Sprite"<<endl;
cout<<"5. Fanta"<<endl<<endl;
cout<<"Please Enter The Number of Drinks : ";
cin>>drink;
if (drink == 1){
cout<<"CocaCola";
}
else
if (drink == 2){
cout<<"Mineral Water";
}
else
if (drink == 3){
cout<<"Root Beer";
}
else
if (drink == 4){
cout<<"Sprite";
}
else
if (drink == 5){
cout<<"Fanta";
}
else{
cout<<"Error.. Choice Was Not Valid, Her is Your Money Back";}
cout<<"\n\n\t\t\t\tThank You..."<<endl;
return 0;
}
return 0;
}

Novella Daria Utami, Ilmu Komputer, Universitas Lampung

Source Code C++


/*
* Hello.cpp
*
* Created on: 20 okt 2015
*
Author: Novella Daria Utami | 1517051135
*/
#include <iostream>
using namespace std;
main(){
int drink;
cout<<"\t\t\t===Hello Welcome Customer==="<<endl;
cout<<"Please Select Your Drink..."<<endl;
cout<<"1. CocaCola"<<endl;
cout<<"2. Mineral Water"<<endl;
cout<<"3. Root Beer"<<endl;
cout<<"4. Sprite"<<endl;
cout<<"5. Fanta"<<endl<<endl;
cout<<"Please Enter The Number of Drinks : ";
cin>>drink;
switch (drink)
{
case 1:cout<<"CocaCola";break;
case 2:cout<<"Mineral Water";break;
case 3:cout<<"Root Beer";break;
case 4:cout<<"Sprite";break;
case 5:cout<<"Fanta";break;
default :cout<<" Error.. Choice Was Not Valid, Her is Your Money
Back";break;
}
cout<<"\n\n\t\t\t\tThank You... "<<endl;
return 0;
}

Novella Daria Utami, Ilmu Komputer, Universitas Lampung

Screenshoot Output Program

Novella Daria Utami, Ilmu Komputer, Universitas Lampung

You might also like