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
|
// MOD2: place the pizza size names, slice sizes and cost in 3 arrays.
#include <iostream>
#include <iomanip>
using namespace std;
void setArray(string pizzaName[], double sliceSize[], double slicePrice[], int size);
void getChoice(string pizzaName[], double slicePrice[]);
int main()
{
const int NUM_SIZE = 5;
string pizzaName[NUM_SIZE] = {"small", "medium", "large", "xlarge", "xxlarge"};
double sliceSize[NUM_SIZE] = {3.0, 3.25, 3.5, 4.0, 4.5};
double slicePrice[NUM_SIZE] = {1.99, 2.50, 2.99, 3.99, 4.99};
setArray(pizzaName, sliceSize, slicePrice, NUM_SIZE);
getChoice(pizzaName, slicePrice);
return 0;
}
void setArray(string pizzaName[], double sliceSize[], double slicePrice[], int size)
{
for (int count = 0; count < size; count++)
cout << setw(7) << left << "Choice: "
<< setw(7) << pizzaName[count] << " - "
<< setw(4) << sliceSize[count] << " - "
<< setw(7) << slicePrice[count] << endl;
cout << endl;
}
void getChoice(string pizzaName[], double slicePrice[])
{
// initialize choice variable for user input
int choice = 0;
cout << "Enter choice number for the size of the pizza you want:" << endl;
cout << endl;
cout << "small - 1: " << endl;
cout << "medium - 2: " << endl;
cout << "large - 3: " << endl;
cout << "xlarge - 4: " << endl;
cout << "xxlarge - 5: " << endl;
cout << endl << " >> ";
cin >> choice;
switch(choice)
{
case 1: cout << fixed << showpoint << setprecision(2) << endl;
cout << "You ordered a " << pizzaName[choice-1] << " pizza which will cost you $"
<< slicePrice[choice-1] << "." << endl;
break;
case 2: cout << fixed << showpoint << setprecision(2) << endl;
cout << "You ordered a " << pizzaName[choice-1] << " pizza which will cost you $"
<< slicePrice[choice-1] << "." << endl;
break;
case 3: cout << fixed << showpoint << setprecision(2) << endl;
cout << "You ordered a " << pizzaName[choice-1] << " pizza which will cost you $"
<< slicePrice[choice-1] << "." << endl;
break;
case 4: cout << fixed << showpoint << setprecision(2) << endl;
cout << "You ordered a " << pizzaName[choice-1] << " pizza which will cost you $"
<< slicePrice[choice-1] << "." << endl;
break;
case 5: cout << fixed << showpoint << setprecision(2) << endl;
cout << "You ordered a " << pizzaName[choice-1] << " pizza which will cost you $"
<< slicePrice[choice-1] << "." << endl;
break;
default: cout << endl << "ERROR!! " << pizzaName[choice-1]
<< " is not a valid entry. Exiting program." << endl;
}
}
|