I am not sure why I have this problem.
Here is my code:
//Daniel Maclin
//Homework 3
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#include "product.cpp"
int main(){
ifstream inFile;
int plu =0;
string name;
int sType; // the sales type
double price; //the price per pound/weight
double inventory;//the amount of the product the store contains
int x = 0;//a counter for the number of products loaded into the Product class
Product product[100];
double balance=0;//the money amount of a product the user buys
double totBalance=0;//the total balance of the user
int quit = 0;//allows for the program to terminate
int found = 0; //records the location of plu code
double userOption;//the weight of a product the user wants to buy
const double discount= 0.05;//the discount for the user
double finalBalance = 0.0;//the final balance after the discount
double discountAmt = 0;//the discount value
bool checkOut = true;//allows the user to check out
char choice = ' ';
inFile.open("inventory.txt");
if(inFile.fail()){
cout << "Cannot open file";
exit(1);
}
while(inFile.good()){
inFile >> plu >> name >> sType >> price >> inventory;
product[x] = Product(plu, name, sType, price, inventory);//this line
x++;
}
while(quit != -1){
cout << "Enter a PLU code or 0 to check out: ";
cin >> plu;
while(checkOut){
if(plu == -1){
quit = -1;
break;
}
//Allows checkout
if(plu == 0){
checkOut = false;
}
for(int i=0; i < x; i++){
if(plu == product[i].getPluCode()){
found = i;
cout << "Product matched" << endl;
}
}
cout << product[found].getName() << "\n";
cout << "Enter the weight for " << product[found].getName() << ": "<< endl;
cin >> userOption;
inventory = product[found].getInventory() - userOption;
//calculates the user's dollar amount
balance = product[found].getPrice() * userOption;
totBalance += balance;
cout<<"Total Balance so far: "<< totBalance << endl;
//is verification for the discount
}
if(totBalance > 50){
discountAmt = totBalance * discount;
finalBalance = totBalance - discountAmt;
}
cout << "Total: $ " << setprecision(2) << fixed << totBalance <<
"\nDiscount: $ " << setprecision(2) << fixed << discountAmt << "\nAmount Due $ "
<< setprecision(2) << fixed << finalBalance << endl;
cout << "Press y to check out the next customer (n to quit)"<<endl;
if(choice == 'y' || choice == 'y'){
checkOut = false;
}
else{
cout<<"Thanks for shopping, have a nice day!" << endl;
quit = -1;
}
}
//after done with for loop, check to see if x is equal to -1, if not, product not found
//if found, it gets the index
//must create the calculations for the amount of a product the user wants.
//Also must create the remainder for the amount of inventory left
//Also, must create variable to keep user's amount spent
system("PAUSE");
return 0;
}
This post has been edited by Ipodhero178: 14 October 2011 - 08:24 PM

New Topic/Question
Reply



MultiQuote






|