0% found this document useful (0 votes)
94 views9 pages

Drink Price Fefef

The program simulates a soft drink vending machine with 5 drink options. It initializes an array with the drink name, cost, and starting quantity for each. The program then enters a loop where it displays the drink list, prompts the user to select a drink or quit, gets payment if a drink is selected, returns change and deducts 1 from the selected drink's quantity. After the loop, it displays the total money earned. Input validation checks that payment is not negative or over $1.

Uploaded by

Nur Atikah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views9 pages

Drink Price Fefef

The program simulates a soft drink vending machine with 5 drink options. It initializes an array with the drink name, cost, and starting quantity for each. The program then enters a loop where it displays the drink list, prompts the user to select a drink or quit, gets payment if a drink is selected, returns change and deducts 1 from the selected drink's quantity. After the loop, it displays the total money earned. Input validation checks that payment is not negative or over $1.

Uploaded by

Nur Atikah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Drink Machine Simulator

 Write a program that simulates a soft drink machine.


The program should use a structure that stores the
following data:
o Drink name
o Drink cost
o Number of drinks in machine
 The program should create an array of five structures.
The elements should be initialized with the following data:

Initialization Data
Number
Drink
Cost in
Name
machine

Pepsi RM2.00 20

Root beer RM2.00 20

Sprite RM1.20 30

Milo RM3.00 20

Coca Cola RM2.50 20


 Each time the program runs, it should enter a loop that
performs the following steps:

o A list of drinks is displayed on the screen. The user


should be allowed to either quit the program or pick a
drink.
o If the user selects a drink, he or she will next enter
the amount of money that is to be inserted into the
drink machine.
o The program should display the amount of change
that would be returned and subtract one from the
number of that drink left in the machine.
o If the user selects a drink that has sold out, a
message should be displayed.
o The loop then repeats.
o When the user chooses to quit the program it
should display the total amount of money the machine
earned.

 Input Validation:

When the user enters an amount of money, do not


accept negative values or values greater than RM1.00.

o
/* Assignment 2 (Grouping)

Group Name =

Group member :

Muhammad Syahmi Bin Sufakhi A18CS0161

Ramkumarhrao a/l Subramaniam A18CS0238

Nur Atikah Binti Sawal A18CS0188

Nur Atikah Binti Hanif A18CS0187

*/

#include <iostream>

#include <iomanip>

#include <fstream>

using namespace std ;

// all constant parameter being declared here

const int row = 15 ;


const int col = 30 ;

const char KOSONG = '#' ;

const char PENUH = '*' ;

int totalSeat = 450 ;

char tempat[row][col];

// Function Declaration

void displayChart();

int menu();

void pilihanpenuh(int);

void harga();

int main()

int bawah, tepi , Quit, option ,kos, semua, answer;

int x, kotakharga =0;

int rege[15] ;

//Opening an input file, to read & transer the data into rege array

ifstream myfile("priceofticket.txt");

if (!myfile)

cout << "Unable to open" << endl;

if (myfile.is_open())

while ( true)

{
myfile >> x; //copy data into array

if (myfile.eof())

break;

rege[kotakharga++] = x;

for (int Nrow = 1; Nrow <= row ; Nrow++) //initializing the empty seat

for (int Ncol = 1;Ncol<=col ; Ncol++)

tempat[Nrow][Ncol] = KOSONG;

menu ();

do

cout << "\n";

cout << "==> Display Ticket Price [1] <==\n" ;

cout << "==> Display Ticket Seat [2] <==\n" ;

cout << "==> Buy Ticket [3] <==\n" ;

cout << "==> Total number ticket sale & price [4] <==\n" ;

cout << "==> Quit [5] <==\n" ;

cin >> option ;

switch (option)

//showing each row of price

case 1:

cout << "Seat Price:" << endl;

for (int i = 0; i < 15; ++i)

cout <<"ROW " << (i+1) << "\t: RM "<< rege[i] << endl;

break;
case 2:

//function call to display the seat chart

displayChart();

break;

case 3:

do

cout << "\nPlease select row you want to sit(1-15)): ";

cin >> tepi;

cout << "\nChoose your number of seat(1-20)): ";

cin >> bawah;

if (tempat[tepi][bawah] == '*')

cout << "\nSorry that seat is sold-out, Please select a new seat.";

cout << endl<< endl;;

else

kos = rege[tepi] ; //Take the price ticket of row to display

cout << "Price ticket: " << kos << "\n \n";

cout << "Enter 1(YES) to comfirm purchase, 2()NO) if you are not
comfirmed";

cin >> answer;

if (answer == 1)

cout << "\nYour ticket purchase has been confirmed." << endl;
tempat[tepi][bawah] = PENUH; // changing the seat from
KOSONG(#) to PENUH(*) in array

totalSeat-- ;

semua = semua + kos ;

else if (answer == 2)

cout << "\nEnter 1(YES) if you want to look another seat, 2(NO)
if you want to go to Menu";

cout << endl;

cin >> Quit;

cout << "\nEnter 1(YES) if you want to look another seat, 2(NO) if you
want to go to Menu";

cin >> Quit;

while (Quit==1);

break ;

case 4:

cout << "\nTotal Ticket left: " << totalSeat ;

cout << "\nTotal ticket sold :RM " << semua<< endl;

break ;

case 5:

cout << "\nThank You for purchasing ticket with us. Have a nice day!\n";

break;

default : cout << "Error input\n";


}

while(option != 5);

// Function Definiton

int menu()

{ int pilih ;

cout << "#######################\n" ;

cout << "# #\n" ;

cout << "# Welcome to #\n" ;

cout << "# MEGAPLEX #\n" ;

cout << "# THEATER #\n" ;

cout << "# #\n" ;

cout << "# #\n" ;

cout << "#######################\n" ;

void displayChart()

cout << "\tSeats" << endl;

cout << " 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0\n";

for (int i = 1; i <= 15; i++)

cout << endl << "Row "<< (i) << "\t";

for (int k = 1; k <= 30; k++)

cout << " " << tempat[i][k];

cout << endl;


return ;

You might also like