1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// functions
#include <iostream>
using namespace std;
//fuction prototypes
void displayMenu(string);
int readIntValue(void);
void orderSummary(int, int, int);
int main(void)
{
char selection = ' ';
string name = "";
string address = "";
int quantityRobusta=0;
int quantityArabica=0;
int quantityExcelsa=0;
//Ask user for her/his name
cout << "May you please enter your name ==> ";
getline(cin, name);
// Ask user for Address
cout << "Please enter shipping address ==";
getline(cin, address);
//display user name
cout << "Welcome to Rex Coffee Shop "+ name << endl;
do
{
//Display Menu
displayMenu(name);
//Read user selection
cin >> selection;
//Define Variables
string order = "";
switch(selection)
{
case '1':
cout<< "You have selected Coffee Robusta, How many would you like?" << endl;
quantityRobusta = readIntValue() + quantityRobusta;
break;
case '2':
cout<< "You have selected Coffe Arabica, How many whould you like?" << endl;
quantityArabica = readIntValue() + quantityArabica;
break;
case '3':
cout<< "You have selected Coffee Excelsa, How many would you like?" << endl;
quantityExcelsa = readIntValue() + quantityExcelsa;
break;
case 'X' :
case 'x':
orderSummary(quantityRobusta, quantityArabica, quantityExcelsa);
cout << "All items will be shipped in the next 72 hrs to :" << address << endl;
cout << "Thank you!!!" << endl;
break;
// other than 1, 2, 3 and X...
default : cout<<"You have made an invalid selection. Please try again";
// no break in the default case
}
cout << endl <<endl;
} while (selection!= 'X' && selection != 'x');
return 0;
}
//Menu function
void displayMenu(string userName)
{
cout << userName << ", Please make a selection from our fine coffee beans" << endl;
cout<<"Coffee Selections Menu"<< endl;
cout<<"========" << endl;
cout<<"1 - Coffee Robusta" << endl;
cout<<"2 - Coffee Arabica" << endl;
cout<<"3 - Coffee Excelsa" << endl;
cout<<"X - Exit " <<endl<<endl;
}
// read integer value from standard input
int readIntValue(int quanityRobusta, int quantityArabica, int quantityExcelsa)
{
string input = " ";
cin >> input;
int rtn = (input.c_str());
return rtn;
}
//Order summary fuction
void orderSummary(int quantityRobusta, int quantityArabica, int quantityExcelsa)
{
float total=0.0;
cout << "Coffee Robusta : " << quantityRobusta << " x $14.99 = $" << quantityRobusta*14.99 << endl;
total=quantityRobusta*14.99 + total;
cout << "Coffee Arabica : " << quantityArabica << " x $10.99 = $" << quantityArabica*10.99 << endl;
total= quantityArabica*10.99 + total;
cout << "Coffee Excelsa : " << quantityExcelsa << " x $18.99 = $" << quantityExcelsa*18.99 << endl;
total= quantityExcelsa*18.99 + total;
cout << "Your order total is : $" << total << endl;
}
|