Answer to Question #148418 in C++ for Gerald

Question #148418
A small store only sells Coke 1.5 liters and San Miguel 1 liter, Make a program that will input
type of item, C-for Coke with a price of 65.00 and S- for San Miguel with a price of 120.00.
Display the price, and your program will be terminated if you input T in the type of item
1
Expert's answer
2020-12-03T07:29:43-0500
#include <iostream>

using namespace std;

int main()
{
	char key;

	do {
		cout << "Please choose a drink or \'T\' for the exit :" << endl << endl;
		cout << "\t[C] Coke" << endl;
		cout << "\t[S] San Miguel" << endl;
		cout << "\t[T] Quit" << endl;

		key = cin.get();
		cin.clear();
		while (cin.get() != '\n');
		key = tolower(key);
		if (key != 'c' && key != 's' && key != 't') {
			cout << "Incorrect input. Enter \'C\', \'S\' or \'T\'." << endl << endl;
		}

		switch (key)
		{
		case 'c': cout << "\tCoke 1.5l - 65.00" << endl; break;
		case 's': cout << "\t San Miguel 1l - 120.00" << endl; break;
		default:
			break;
		}
		cout << endl;
	} while (key != 't');

	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog