repl.it
@justingraham/

Regional 2014

C++

No description

fork
loading
Files
  • main.cpp
  • gameinventory.txt
main.cpp
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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<string> itemname{"sword", "mace", "shield", "potion", "cloak", "dagger"};
vector<int> cost{15, 30, 50, 15, 24, 24};
vector<int> quantity{1, 1, 1, 12, 5, 1};

void display_inventory();
void add_item();

int main()
{
	
	cout << "****************************";
	cout << "\n     Game Item Inventory\n";
	cout << "****************************";

	cout << "\n\n[d] Display all the inventory from file.";
	cout << "\n[a] Append an item to the invetory file.";
	cout << "\n[q] Quit and commit changes to the file.";

	string choice;
	cout << "\n\nChoice (enter letter choice): ";
	cin  >> choice;
	while(choice != "q" && choice != "Q")
	{
		while(choice != "d" && choice != "D" && choice != "a" && choice != "A" && choice != "q" && choice != "Q")
		{
			cin.clear();
			cin.ignore(99999, '\n');
			cout << "Incorrect choice. Please enter the letter choice (d, a, or q): ";
			cin  >> choice;
		}
		
		if(choice == "d" || choice == "D")
		{
			display_inventory();
		}
		else if(choice == "a" || choice == "A")
		{
			add_item();
		}
		
		cout << "****************************";
		cout << "\n     Game Item Inventory\n";
		cout << "****************************";
		
		cout << "\n\n[d] Display all the inventory from file.";
		cout << "\n[a] Append an item to the invetory file.";
		cout << "\n[q] Quit and commit changes to the file.";
		
		cout << "\n\nChoice (enter letter choice): ";
		cin  >> choice;
	}
	return 0;
}

void display_inventory()
{
	cout << "\nYour List: \n";
	cout << "Item\tCost\tQuantity\n";
	// prints the array
 	for(int i; i < itemname.size(); i++)
	{ 
	    cout << itemname[i] << "\t" << cost[i] << "\t" << quantity[i] << endl;
	}
	
	string menu;
	cout << "\n Enter anything in to continue . . . ";
	cin  >> menu;
}

void add_item()
{
	string additem;
	cout << "Enter the name for this new item: ";
	cin  >> additem;
	itemname.push_back(additem);
	
	int ccost;
	cout << "Enter unit cost for this item: ";
	cin  >> ccost;
	while(cin.fail())
	{
		cin.clear();
		cin.ignore(99999, '\n');
		cout << "Incorrect. Enter the quantity in stock number for this item: ";
		cin  >> ccost;
	}
	cost.push_back(ccost);
	
	int qquantity;
	cout << "Enter quantity in stock for this item: ";
	cin  >> qquantity;
	while(cin.fail())
	{
		cin.clear();
		cin.ignore(99999, '\n');
		cout << "Incorrect. Enter the quantity in stock number for this item: ";
		cin  >> qquantity;
	}
	quantity.push_back(qquantity);
	
	cout << "\nItem added to the inventory!\n";		
	
	string menu;
	cout << "\n Enter anything in to continue . . . ";
	cin  >> menu;
}
Fetching token
?