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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#include <iostream>
#include <cstdlib>
using namespace std;
bool cice(char choice)
{
switch(choice)
{
case 'y':
case 'Y':
return true;
break;
case 'n':
case 'N':
return false;
break;
default:
return -1;
}
}
int main(int nNumberofArgs,char* pszARgs[])
{
char flavor,choice;
int scoops,nLolli,nGum;
double iPrice = 0,total = 0,iTotal = 0,sTotal = 0,fTotal = 0,cTotal = 0,lTotal = 0,gTotal = 0;
string IceC;
bool ice = false,lollipop = false,gumdrops = false,sprinkles = false,fudge = false,cream = false;
for(;;)
{
cout << endl << endl;
cout << "Welcome to the ice cream store!" << endl;
cout << "Would you like Vanilla, Strawberry, or Chocolate?" << endl;
cout << "(V)anilla - $1.15" << endl;
cout << "(S)trawberry - $1.20" << endl;
cout << "(C)hocolate - $1.25" << endl;
cout << "(N)one" << endl;
cout << "Flavor: ";
cin >> flavor;
switch(flavor)
{
case 'v':
case 'V':
iPrice = 1.15;
IceC = "vanilla";
break;
case 's':
case 'S':
iPrice = 1.20;
IceC = "strawberry";
break;
case 'c':
case 'C':
iPrice = 1.25;
IceC = "chocolate";
break;
case 'n':
case 'N':
goto snacks;
default:
cout << "Please enter V,S, or C!" << endl;
}
ice = true;
cout << endl << "How many scoops of " << IceC << " would you like? : ";
cin >> scoops;
if(scoops < 0)
{
cout << "Error: You cannot have negative scoops!" << endl;
}
iTotal = scoops * iPrice;
cout << endl << "Extras!" << endl << "------------------------------------" << endl;
cout << "Would you like sprinkles? $0.15 per scoop (Y or N): ";
cin >> choice;
sTotal = .15 * scoops;
sprinkles = cice(choice);
cout << "Would you like hot fudge? $0.20 per scoop (Y or N): ";
cin >> choice;
fTotal = .2 * scoops;
fudge = cice(choice);
cout << "Would you like whipped cream? $0.10 per scoop (Y or N): ";
cin >> choice;
cTotal = .1 * scoops;
cream = cice(choice);
snacks:
cout << endl << "Snacks!" << endl << "------------------------------------" << endl;
cout << "Would you like a lollipop? $0.79 (Y or N): ";
cin >> choice;
lollipop = cice(choice);
if(lollipop)
{
cout << "How many lollipops would you like?: ";
cin >> nLolli;
lTotal = .79 * nLolli;
}
cout << "Would you like a pack of gumdrops? $0.55 (Y or N): ";
cin >> choice;
gumdrops = cice(choice);
if(gumdrops)
{
cout << "How many packs would you like?: ";
cin >> nGum;
gTotal = .55 * nGum;
}
cout << "------------------------------------" << endl;
total = scoops * iPrice;
if(sprinkles)
{
total += .15 * scoops;
}
if(fudge)
{
total += .2 * scoops;
}
if(cream)
{
total += .1 * scoops;
}
if(lollipop)
{
total += .79 * nLolli;
}
if(gumdrops)
{
total += .55 * nGum;
}
cout << "Receipt: " << endl;
if(ice)
{
cout << scoops << " scoops of " << IceC << " = $" << iTotal << endl;
}
cout << "Extras: " << endl;
if(sprinkles)
{
cout << "Sprinkles: " << scoops << " scoops * $0.15 = $" << sTotal << endl;
}
if(fudge)
{
cout << "Hot Fudge: " << scoops << " scoops * $0.20 = $" << fTotal << endl;
}
if(cream)
{
cout << "Whipped Cream: " << scoops << " scoops * $0.10 = $" << cTotal << endl;
}
if(lollipop)
{
cout << nLolli << " lollipops = $" << lTotal << endl;
}
if(gumdrops)
{
cout << nGum << " gumpacks = $" << gTotal << endl;
}
cout << "-----------------------" << endl;
cout << "Total: $" << total << endl;
cout << "-----------------------" << endl;
cout << endl << "Would you like to buy some more?(Y or N): ";
cin >> choice;
switch(choice)
{
case 'y':
case 'Y':
break;
case 'n':
case 'N':
system("PAUSE");
return 0;
default:
cout << "Please enter Y or N!" << endl;
system("PAUSE");
return 0;
}
}
}
|