Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

#include <bits/stdc++.h> using namespace std; // utility function void strToBinary(string s) { int n = s.length(); for (int i = 0; i <= n; i++) { // convert each cha

#include

using namespace std;

// utility function

void strToBinary(string s)

{

    int n = s.length();

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

    {

        // convert each char to

        // ASCII value

        int val = int(s[i]);

        // Convert ASCII value to binary

        string bin = "";

        while (val > 0)

        {

            (val % 2)? bin.push_back('1') :

                       bin.push_back('0');

            val /= 2;

        }

        reverse(bin.begin(), bin.end());

        cout << bin << " ";

    }

}

int main ()

{

vector beverages(3);

beverages[0] = "Water"; //Entering beverage Water

beverages[1] = "Pepsi"; //Entering beverage Pepsi

beverages[2] = "Coke"; //Entering beverage Coke

vectorprice(3);

price[0] = 1.50; //Price of beverage

price[1] = 1.75; //Price of beverage

price[2] = 1.00; //Price of beverage

vectordrink_counts(3);

drink_counts[0] = 10;

drink_counts[1] = 10;

drink_counts[2] = 10;

char

input;

do

{

cout<<"\n Please Select Beverages using keypad!\n\n";

cout<<"Available choices are as followes: \n1. Water : A1 \n2. Pepsi: B2 \n3. Coke: C3 \n";

string choice;

cin>>choice;

int beverageId = -1;

if(choice == "A1") //Beverage selection as A1

beverageId = 0;

else if(choice == "B2") //Beverage selection as B2

beverageId = 1;

else if(choice == "C3") //Beverage selection as C3

beverageId = 2;

else

cout<< "Wrong Selection\n"; // Throw error message of selection is wrong

if (beverageId != -1)

{

cout<<"$"<

string s = "<<<>>>>";

string s = "<<<>>>>";

strToBinary(s);

}

else

continue;

if (drink_counts[beverageId] > 0)

{

drink_counts[beverageId] = drink_counts[beverageId] - 1;

int money = 0;

char ch = 'y';

// Use While loop

while (ch != 'n')

{

cout<< "Enter the amount in $1 or $5 or $10 bills\n";

int amountEntered;

cin>>amountEntered;

if (amountEntered != 1 && amountEntered != 5 && amountEntered != 10) //This will show amount entered

{

cout<< "Invalid amount. Please try again\n";

ch = 'y';

continue;

}

money += amountEntered;

if(money >= price[beverageId])

break;

cout<<"Remaining Amount = "<

cout<<"Please Enter more money: (y/n)\n";

cin>>ch;

}

if (money < price[beverageId])

cout<<"Not enough money to buy drink, Transaction Cancelled\n";

if(money == price[beverageId])

cout<< "Thank you! Enjoy your Beverage!\n";

else

cout<< "Please take your Change = " << money - price[beverageId]<<"\n";

}

else

cout<< "Selected Beverage is out of stock\n";

cout<<"Do you need more beverages (y/n) ";

cin>>input;

if(input == 'n')

cout<<"Thanks for buying drinks"<<"\n";

}

while(input == 'y' || input == 'Y');

return 0;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question