ASSIGNMENT 2
2021/2022
,COS1511 Assignment 2
Question 1
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//Fill in the code to define an integer cariable called selection
int selection, number;
float cost;
cout << "Please enter the choice of hotdog "
<< "(a number from 1 to 4 or 0 to quit)" << endl;
cout << "Hot dog Menu " << endl << endl;
cout << "1: Plain Hotdog " << endl;
cout << "2: Chilli Hotdog " << endl;
cout << "3: Cheese Hotdog " << endl;
cout << "4: Russian Hotdog " << endl;
cout << "0: QUIT " << endl << endl << endl;
cin >> selection;
while (selection > 4 || selection <0 ) //complete the condition
{
cout << "Invalid coice - Please re-enter ";
cin >> selection;
}
cout << "You have selected option number " << selection << endl;
cout << "How many hotdogs would you like? " << endl;
//Fill in the code to read number
cin >> number;
//Fill in the code to begin a switch statement that is controlled by selection
switch (selection)
{
case 1: cost = number * 15.0;
cout << "The total cost is R" << cost << endl;
break;
case 2: cost = number * 12.50;
cout << "The total cost is R" << cost << endl;
break;
, case 3: cost = number * 17.00;
cout << "The total cost is R" << cost << endl;
break;
case 4: cost = number * 22.50;
cout << "The total cost is R" << cost << endl;
break;
case 0: cout << "Please come again" << endl;
break;
default:
cout << "Invalid selection";
cout << "Try again please" << endl;
}
return 0;
}
Output: