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
|
/*
* File: main.cpp
* Author: Chip
* Created on September 28, 2012, 8:31 AM
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const int PRODUCT = 100;
struct Item {
double plucode;
string name;
double incremint;
double price;
double storage;
double inventory;
double invent;
};
double userPounds, userPrice, userDiscount, userTotal, userInput, userTotalPounds, userFinal;
int number = 0;
int i = 0;
bool trueValue, falseValue;
char again, sign, done;
int currentItem;
int main(int argc, char** argv) {
ifstream inputFile("Inventory.txt");
ofstream outputFile;
outputFile.open("output.txt");
sign = 'y', 'Y', 'n', 'N';
again = 'y', 'Y', 'n', 'N';
Item item[100];
while (!inputFile.eof()) {
inputFile >> item[number].plucode >> item[number].name >> item[number].incremint >> item[number].price >> item[number].storage;
number++;
}
inputFile.close();
bool done = false;
cout << "Welcome to Simple Store" << endl;
while (done == false) {
do {
do {
cout << "Enter plucode of the item that you wish to purchase.";
cin >> userInput;
for (int i = 0; i < PRODUCT; i++) {
if (userInput == item[i].plucode) {
currentItem = i;
}
}
cout << "How many units of " << item[currentItem].name << " would you like?" << endl;
cin >> userPounds;
for (int i = 0; i < 21; i++) {
if (userPounds >= 0) {
item[currentItem].inventory = (item[currentItem].storage - userPounds);
} else item[currentItem].inventory = item[currentItem].storage;
}
userPrice = item[currentItem].price * userPounds;
cout << "The price would be $" << userPrice << endl;
userTotal += userPrice;
userTotalPounds += userPounds;
if (userTotal > 50) {
userFinal += userTotal * .95;
userDiscount += userTotal * .05;
}
cout << "Would you like to check out? (Y/N)" << endl;
cin >> again;
if (again == 'N' || again == 'n') {
cout << "Proceed to next item" << endl;
}
} while (again == 'N' || again == 'n');
cout << "Would you like to sign out? (Y/N)" << endl;
cin >> sign;
if (sign == 'Y' || sign == 'y') {
cout << setprecision(2) << fixed;
cout << "Your total weight sold was " << userTotalPounds << " units." << endl;
cout << "Your total gross sales amount is $" << userTotal << endl;
cout << "Your final checkout amount is $" << userFinal << endl;
cout << "Your total discounts given were $" << userDiscount << endl;
done == true;
}
} while (sign == 'N' || sign == 'n');
for (i = 0; i < 21; i++)
outputFile << item[i].plucode << " " << item[i].name << " " << item[i].incremint << " " << item[i].price << " " << item[i].inventory << endl;
outputFile.close();
cout << "Program is being terminated";
break;
}
}
| |