Saving data entered by the user?

Jun 5, 2013 at 1:59am
I'm trying to make a console app that manages your money in a game's auction house. You can add up to 20 items to manage and you'll be able to see see potential profit from an item, account for fees, and things like that. All those will be done in the function UponOpening. But before I do all this, I'm trying to figure out how to save all the data I entered so that next time I enter the app all the items and info entered are still there.

Can anyone point me in the right direction here? I'm thinking it has something to do with "Input/Output with files." Thanks in advance

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
#include <iostream>
#include <string>

using namespace std;

double GoldAtStart;
string NameItem[20];
double BuyPrice[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
double QuantityItem[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
double TotalAfterFee[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
double SellPrice[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int UserInput;
int x = 0;

double FeeDeductor(double SellPrice, double Quantity);
void UponOpening();

int main(){
		cout << "Enter the amount of gold in your inventory" << endl;
		cin >> GoldAtStart;
		UponOpening();

}

double FeeDeductor(double FSellPrice, double FQuantity){
	TotalAfterFee[x] = (FSellPrice * FQuantity) - .15*(FSellPrice * FQuantity);
	return TotalAfterFee[x];
}

void UponOpening(){
	cout << "What would you like to do?" << endl << endl;
	cout << "1. Add an item to the database" << endl;
	cout << "2. Option 2" << endl;
	cout << "3. Option 3" << endl;
	cout << "4. Option 4" << endl;
	cin >> UserInput;
	if(UserInput ==1){
		cout << "Enter the name of the item you are buying" << endl;
		cin.ignore();
		getline(cin, NameItem[x]);
		cin.clear();
		cout << "Price purchased for?" << endl;
		cin >> BuyPrice[x];
		cout << "Quantity purchased?" << endl;
		cin >> QuantityItem[x];
		cout << "What do you intend to sell it for?" << endl;
		cin >> SellPrice[x];
		cout << "Item successfully entered into the database" << endl << endl;
		x++;
		UponOpening();
	}
}
Jun 5, 2013 at 4:28am
Yup! Go to documentation and go down to input/output tutorials. It will show you how to write to text files and read them as well. You of course will have to manipulate the your program in such a way to pull up the file to read and so on.
Topic archived. No new replies allowed.