-
May 14th, 2011, 04:33 PM
#1
Inventory System
Hello, Ive been working on this inventory for practice for quite some time now and this is the last thing i need to do ive been trying everything i know to get it to work. which is adjusting the supply for each item. I have gotten options 1 and 2 to work and save in thefile i close and open the file and press option 2 and the data saved in the file show up and it works. But when i try to edit the inventory(option 3) it doesnt work it wont save in the file and if it does the numbers are rediculous.
Lines 81 - 148.
Code:
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <windows.h>
using namespace std;
void addInventory()
{
system("cls");
char filename[20];
string Item1, Item2, Item3, Item4, Item5, choice5;
unsigned int choice, choice2, choice3, choice4, s,s1, s2, s3, s4, answer,answer1,answer2, answer3,answer4, answer5;
cout << "\nAdd Item 1 ";
cin >> Item1;
cout << "Add Item 2 ";
cin >> Item2;
cout << "Add Item 3 ";
cin >> Item3;
cout << "Add Item 4 ";
cin >> Item4;
cout << "Add Item 5 ";
cin >> Item5;
cout << "\n\nItem Quantity\n\n"; // choosing quantities for items named above
cout << Item1 << ": ";
cin >> s;
cout << Item2 << ": ";
cin >> s1;
cout << Item3 << ": ";
cin >> s2;
cout << Item4 << ": ";
cin >> s3;
cout << Item5 << ": ";
cin >> s4;
system("cls");
cout << "\nUpdating Darkroom Inventory.... \n";// printing out items and quantities
cout << Item1 << ": " << s << endl;
cout << Item2 << ": " << s1 << endl;
cout << Item3 << ": " << s2 << endl;
cout << Item4 << ": " << s3 << endl;
cout << Item5 << ": " << s4 << endl;
system("cls");
cout << "\nEnter the name of the file you want your data to be saved in." << endl;
cin >> filename;
ofstream Inventory(filename, ios::out);
Inventory << Item1 << ": " << s << "\n";
Inventory << Item2 << ": " << s1 << "\n";
Inventory << Item3 << ": " << s2 << "\n";
Inventory << Item4 << ": " << s3 << "\n";
Inventory << Item5 << ": " << s4 << endl;
}
void checkInventory()
{
string Item1, Item2, Item3, Item4, Item5, choice5;
unsigned int choice, choice2, choice3, choice4, s,s1, s2, s3, s4, answer,answer1,answer2, answer3,answer4, answer5;
system("cls");
ifstream filename("inventory.txt");
if (filename.is_open()){
while(true){
getline(filename, Item1);
getline(filename, Item2);
getline(filename, Item3);
getline(filename, Item4);
getline(filename, Item5);
if (!filename.good()) break;
cout << Item1 << ": " << endl;
cout << Item2 << ": " << endl;
cout << Item3 << ": " << endl;
cout << Item4 << ": " << endl;
cout << Item5 << ": " << endl;
}
filename.close();
}else {
cout << "\nNo Inventory Added\n";
}
}
void editInventory()
{
string Item1, Item2, Item3, Item4, Item5, choice5;
unsigned int choice, choice2, choice3, choice4, choices, s,s1, s2, s3, s4, answer,answer1,answer2, answer3,answer4, answer5;
system("cls");
cout << "Edit Inventory" << endl;
cout << "\n1. Add to inventory\n";
cout << "2. Subtract from inventory\n" << endl;
cin >> choices;
if (choices == 1){
cout << "\nHow much do you want to add to Item 1 " << Item1 << endl;
cin >> answer;
cout << Item1 << s + answer << endl;
cout << "How much do you want to add to Item 2 " << Item2 << endl;
cin >> answer2;
cout << s1 + answer2 << endl;
cout << "How much do you want to add to Item 3 " << Item3 << endl;
cin >> answer3;
cout << s2 + answer3 << endl;
cout << "How much do you want to add to Item 4 " << Item4 << endl;
cin >> answer4;
cout << s3 + answer4 << endl;
cout << "How much do you want to add to Item 5 " << Item5 << endl;
cin >> answer5;
cout << s4 + answer5 << endl;
ofstream Inventory("inventory.txt", ios::in);
Inventory << Item1 << ": " << s - answer << endl;
Inventory << Item2 << ": " << s1 - answer2 << endl;
Inventory << Item3 << ": " << s2 - answer3 << endl;
Inventory << Item4 << ": " << s3 - answer4 << endl;
Inventory << Item5 << ": " << s4 - answer5 << endl;
}else {
cout << "\nHow much do you want to subtract to Item 1 " << Item1 << endl;
cin >> answer;
cout << s - answer << endl;
cout << "How much do you want to subtract to Item 2 " << Item2 << endl;
cin >> answer2;
cout << s1 - answer2 << endl;
cout << "How much do you want to subtract to Item 3 " << Item3 << endl;
cin >> answer3;
cout << s2 - answer3 << endl;
cout << "How much do you want to subtract to Item 4 " << Item4 << endl;
cin >> answer4;
cout << s3 - answer4 << endl;
cout << "How much do you want to subtract to Item 5 " << Item5 << endl;
cin >> answer5;
cout << s4 - answer5 << endl;
ofstream Inventory("inventory.txt", ios::in);
Inventory << Item1 << ": " << s - answer << endl;
Inventory << Item2 << ": " << s1 - answer2 << endl;
Inventory << Item3 << ": " << s2 - answer3 << endl;
Inventory << Item4 << ": " << s3 - answer4 << endl;
Inventory << Item5 << ": " << s4 - answer5 << endl;
}
}
int main()
{
cout << "Login" << endl;
int exit;
string user, password;
cout << "\nUsername: ";
cin >> user;
cout << "\nPassword: ";
cin >> password;
if (user == "Darkroom" && password == "bluemoon"){
cout << "Access Granted" << endl;
cout << "Logging on..." << endl;
Sleep(1000);
}else {
cout << "Accessed Denied Please Exit the program." << endl;
cout << "Press 1 to Exit the Program.\t";
cin >> exit;
if (exit == 1){
std::exit(EXIT_FAILURE);
}
}
int choice, choice2;
do {
system("cls");
cout << "Darkroom Inventory Version 1.\n\n";
cout << "1. Add Inventory\n";
cout << "2. Check Inventory\n";
cout << "3. Edit Inventory\n";
cin >> choice;
switch ( choice ) {
case 1: addInventory(); break;
case 2: checkInventory();break;
case 3: editInventory(); break;
}
cout << "\n\n\n\n1.Main Menu\n";
cout << "2.Exit \n";
cin >> choice2;
}while (choice2 ==1);
if(choice2 == 2){
std::exit(EXIT_FAILURE);
}
char response;
cin >> response;
return EXIT_SUCCESS;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|