Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

#include using namespace std; // utility function void strToBinary(string s) { int n = s.length(); for (int i = 0; i

#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!nn”;

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 Selectionn”; // 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 billsn”;

int amountEntered;

cin>>amountEntered;

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

{

cout<< “Invalid amount. Please try againn”;

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 Cancelledn”;

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 stockn”;

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;

}

aalan

Leave a comment