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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void MoreThan5() // Function for showing a customer entering more than 5.
{
cout << "You've entered more than 5. Please enter 1 to 5." <<endl<<endl;
}
void LessThan1() // Function for showing a customer entering less than 1.
{
cout << "You've entered less than 1. Please enter 1 to 5." <<endl<<endl;
}
int ChocoSelect() // Function for selecting a chocolate.
{
int cChoice; // Your chocolate selection.
int qAMB, qSD, qCS, qCMB; // Quantity of All Milk Bar, Sugar Drops, Caramel Surprise, and Chunky Milk Bar respectively.
double tPrice; // Total price for all chocolates.
system("cls");
cout << "**************************************" <<endl;
cout << " CHOCOLATE MENU " <<endl;
cout << "**************************************" <<endl;
cout << "ITEM \t\t\t Price/each" <<endl;
cout << "1. All Milk Bar \t $0.25" <<endl;
cout << "2. Sugar Drops \t\t $0.35" <<endl;
cout << "3. Caramel Surprise \t $0.50" <<endl;
cout << "4. Chunky Milk Bar \t $0.75" <<endl<<endl;
do
{
cout << "Make a selection: ";
cin >> cChoice;
system ("cls");
switch (cChoice)
{
case 1: // Choosing "All Milk Bar"
do
{
cout << "How many All Milk Bar(s) would you like? (max 5): ";
cin >> qAMB;
if (qAMB > 5)
{
MoreThan5(); // Calling a function of having a customer entering more than 5.
}
else if (qAMB < 1)
{
LessThan1(); // Calling a function of having a customer entering less than 1.
}
else
{
tPrice = 0.25 * qAMB;
}
} while (qAMB < 1 && qAMB > 5);
break;
case 2: // Choosing "Sugar Drops"
do
{
cout << "How many Sugar Drops would you like? (max 5): ";
cin >> qSD;
if (qSD > 5)
{
MoreThan5(); // Calling a function of having a customer entering more than 5.
}
else if (qSD < 1)
{
LessThan1(); // Calling a function of having a customer entering less than 1.
}
else
{
tPrice = 0.35 * qSD;
}
} while (qSD < 1 && qSD > 5);
break;
case 3: // Choosing "Caramel Surprise"
do
{
cout << "How many Caramel Surprise(s) would you like? (max 5): ";
cin >> qCS;
if (qCS > 5)
{
MoreThan5(); // Calling a function of having a customer entering more than 5.
}
else if (qCS < 1)
{
LessThan1(); // Calling a function of having a customer entering less than 1.
}
else
{
tPrice = 0.50 * qCS;
}
} while (qCS < 1 && qCS > 5);
break;
case 4: // Choosing "Chunky Milk Bar"
do
{
cout << "How many Chunky Milk Bar(s) would you like? (max 5): ";
cin >> qCMB;
if (qCMB > 5)
{
MoreThan5(); // Calling a function of having a customer entering more than 5.
}
else if (qCMB < 1)
{
LessThan1(); // Calling a function of having a customer entering less than 1.
}
else
{
tPrice = 0.75 * qCMB;
}
} while (qCMB < 1 && qCMB > 5);
break;
default: // If a customer enters other than 1 to 4 will get an error!
cout << "INVALID SELECTION! Please wait 10 seconds." <<endl;
system ("pause");
break;
}
} while (cChoice < 1 && cChoice > 4);
cout << "\nTotal price is: $" << tPrice <<endl;
system("pause");
return qAMB, qSD, qCS, qSD, cChoice;
return tPrice;
}
double InsertCoin(double totalPrice)
{
double currentTotal = 0; // Current total inserted
int choice; // Choose a coin
system("cls");
cout << "\nINSERT COINS" <<endl;
cout << "1. 5 cents" <<endl;
cout << "2. 10 cents" <<endl;
cout << "3. 20 cents" <<endl;
cout << "4. 50 cents" <<endl;
cout << "5. 100 cents" <<endl<<endl;
do
{
cout << "Choose a coin: ";
cin >> choice;
switch (choice)
{
case 1:
currentTotal = currentTotal + 0.05;
cout << "Current Total : $" << currentTotal <<endl<<endl;
break;
case 2:
currentTotal = currentTotal + 0.10;
cout << "Current Total : $" << currentTotal <<endl<<endl;
break;
case 3:
currentTotal = currentTotal + 0.20;
cout << "Current Total : $" << currentTotal <<endl<<endl;
break;
case 4:
currentTotal = currentTotal + 0.50;
cout << "Current Total : $" << currentTotal <<endl<<endl;
break;
case 5:
currentTotal = currentTotal + 1;
cout << "Current Total : $" << currentTotal <<endl<<endl;
break;
default:
cout << "Invalid choice!" <<endl<<endl;
}
} while (currentTotal < totalPrice);
return currentTotal;
}
double dispenser(int AMB, int SD, int CS, int CMB, int chocoChoice, double totalPrice, double cTotal)
{
double change; // Change given
change = cTotal - totalPrice;
system ("cls");
if (chocoChoice == 1)
{
cout << "Your 1. All Milk Bar(s) is/are dispensed one at a time." <<endl;
cout << "All Milk Bar number: " << AMB <<endl;
cout << "Remaining money: $" << change <<endl;
}
else if (chocoChoice == 2)
{
cout << "Your 2. Sugar Drops is/are dispensed one at a time." <<endl;
cout << "Sugar Drops number: " << SD <<endl;
cout << "Remaining money: $" << change <<endl;
}
else if (chocoChoice == 3)
{
cout << "Your 3. Caramel Surprise(s) is/are dispensed one at a time." <<endl;
cout << "Caramel Surprise number: " << CS <<endl;
cout << "Remaining money: $" << change <<endl;
}
else
{
cout << "Your 4. Chunky Milk Bar(s) is/are dispensed one at a time." <<endl;
cout << "Chunky Milk Bar number: " << CMB <<endl;
cout << "Remaining money: $" << change <<endl;
}
system("pause");
system("cls");
cout << "Thank you for using our machine." <<endl;
cout << "You have $" << change << " change to colect." <<endl;
return 1;
}
int main()
{
int AMB = 0, SD = 0, CS = 0, CMB = 0;
int chocoChoice = 0;
double totalPrice = 0.00;
double cTotal = 0.00;
cout << "Welcome to the Chocolate Vending Machine." <<endl;
system("pause");
AMB, SD, CS, CMB, chocoChoice = ChocoSelect();
totalPrice = ChocoSelect();
cTotal = InsertCoin(totalPrice);
dispenser(AMB, SD, CS, CMB, chocoChoice, totalPrice, cTotal);
system("pause");
return 0;
}
|