Input wont load name and sets money to 0

When i go to load my stats it loads money as 0 and doesn load the name, i checked the file and everything was there, the name and money it just wont load.

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
122
#include <iostream>
#include <string>
#include "Player.h"
#include <fstream>
#include <time.h>
#include <cstdlib>

/*

int x = 800;
int *pointer = &x;

cout << *pointer << endl;

*/

using namespace std;

void Load(string PN, int M, int XP, int L)
{
    ifstream File_In;

    File_In.open("WMSF.txt");

    File_In >> PN;
    File_In >> M;
    File_In >> XP;
    File_In >> L;

    cout << PN << endl;
    cout << M << endl;
    cout << XP << endl;
    cout << L << endl;
}

void Save(string PN, int M, int XP, int L)
{
    ofstream File_Out;

    File_Out.open("WMSF.txt");

    File_Out << PN << endl;
    File_Out << M << endl;
    File_Out << XP << endl;
    File_Out << L << endl;
}

void Game(string PN, int M, int XP, int L)
{
    int choice = 0;
    int choice2 = 0;

    cout << PN << endl;
    cout << M << endl;
    cout << XP << endl;
    cout << L << endl;

    int r;
    srand(time(0));

    r = rand() % 15;

    cout << "MENU\n" << endl;

    cout << "1) Ship products" << endl;
    cout << "2) Stats" << endl;
    cin >> choice;

    if(choice == 1)
    {
        cout << "where are you shipping to" << endl;
        cout << "1) Chicago" << endl;
        cout << "2) Los Angeles" << endl;
        cout << "3) Tokyo" << endl;
        cin >> choice2;

        switch(choice2)
        {
            case 1:
                cout << "Delivering to chicago" << endl;

        }
    }
}

int main()
{
    int choice = 0;
    int money = 0;
    int xp = 0;
    int level = 1;
    int distance = 0;
    string Player_Name;

    cout << "Warehouse Manager\n" << endl;

    cout << "1) New Game" << endl;
    cout << "2) Load Game" << endl;
    cin >> choice;

    cin.ignore(200, '\n');

    if(choice == 1)
    {
        cout << "Welcome, what is your name?" << endl;
        getline(cin, Player_Name);

        cout << "/nOk " << Player_Name << " Lets get some info before we start\n" << endl;
        cout << money << endl;

        money += 300;

        Save(Player_Name, money, xp, level);
        Game(Player_Name, money, xp, level);
    }
    if(choice == 2)
    {
        Load(Player_Name, money, xp, level);
        Game(Player_Name, money, xp, level);
    }
}
Does you name contain whitespaces?
no
You are loading the data in local variables that are lost when Load() returns. You should use references in Load() instead to load into the variables in main().
i thought i was referencing the stuff though?
bump
closed account (Dy7SLyTq)
on line 108 its \n not /n
and no. when you call a function, all of the arguements are copied. so to reference them you put a & next to there names in the function
Ok so i put a reference operator next to the thing im trying to reference in the body of the function or the function parameters?
closed account (Dy7SLyTq)
parameters
Topic archived. No new replies allowed.