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
|
#include <iostream>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{
char money;
double totalm = 0;
double value = 0, valued = 0, valuen = 0, valueq = 0;
int c = 1, m = 2, p = 3, k = 4, w = 5;
int C = 1, M = 2, P = 3, K = 4, W = 5;
char item;
cout << "Products" << endl;
cout << "" << endl;
cout << "C= Crisps 40p" << endl;
cout << "M= Milk Chocolate Bar 60p" << endl;
cout << "P= Plain Chocolate Bar 60p" << endl;
cout << "K= Cola 30p" << endl;
cout << "W= Water 30p" << endl;
cout << " " << endl;
cout << "Please insert credit. '1'=10p, '2'=20p and '5'=50p" << endl;
cout << "After you have inserted the money enter 'E' to end the deposit" << endl;
cout << " " << endl;
cin >> money;
while (money != 'e' && money != 'E')
{
if (money == '1')
{
double valueq = 0.10;
totalm += valueq;
cout << "10p, the total money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cin >> money;
}
else {
if (money == '2')
{
double valueq = 0.20;
totalm += valueq;
cout << "20p, the total money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cin >> money;
}
else {
if (money == '5')
{
double valueq = 0.50;
totalm += valueq;
cout << "50p, the total money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cin >> money;
}
else
{
cout << "Invalid entry, please try again" << endl;
cin >> money;
}
}
}
}
cout << "Please make your selection" << endl;
cin >> item;
if (item == c || C)
{
double Z = 0.40;
float change = 0;
if (totalm >= Z)
{
cout << "Crisps have been purchased" << endl;
change = totalm - Z;
cout << "Money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cout << "Your change is " << setprecision(2) << fixed << char(156) << change << endl;
cout << "Thank You" << endl;
cout << " " << endl;
}
}
else if (item == m || M)
{
float Y = 0.60;
float change = 0;
if (totalm >= Y)
{
cout << "Milk Chocolate has been purchased" << endl;
change = totalm - Y;
cout << "Money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cout << "Your change is " << setprecision(2) << fixed << char(156) << change << endl;
cout << "Thank You" << endl;
cout << " " << endl;
}
}
else if (item == p || P)
{
float X = 0.60;
float change = 0;
if (totalm >= X)
{
cout << "Plain Chocolate has been purchased" << endl;
change = totalm - X;
cout << "Money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cout << "Your change is " << setprecision(2) << fixed << char(156) << change << endl;
cout << "Thank You" << endl;
cout << " " << endl;
}
}
else if (item == k || K)
{
float V = 0.30;
float change = 0;
if (totalm >= V)
{
cout << "Cola has been purchased" << endl;
change = totalm - V;
cout << "Money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cout << "Your change is " << setprecision(2) << fixed << char(156) << change << endl;
cout << "Thank You" << endl;
cout << " " << endl;
}
}
else if (item == w || W)
{
float U = 0.30;
float change = 0;
if (totalm >= U)
{
cout << "Water has been purchased" << endl;
change = totalm - U;
cout << "Money deposited is " << setprecision(2) << fixed << char(156) << totalm << endl;
cout << "Your change is " << setprecision(2) << fixed << char(156) << change << endl;
cout << "Thank You" << endl;
cout << " " << endl;
}
}
else
{
cout << "Invalid selection, please try again" << endl;
}
system("pause");
exit(0);
}
|