Variables Not Properly Changing Value

Sorry for two posts in one day.
One of the features of this program that I want to add is for the amount of money spent and the money earned back to be added to the variables mSpent and mEarned and then displayed at the start of each new loop of the cycle. However the variables will only display their base value of 0 instead of the value they should be displaying. The lines displaying that are supposed to display the value are 42 and 43 and each "entry" at the bottom is supposed to change the value of the variable to differing amounts.


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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <dos.h>
using namespace std;


int main()
{
    int tempest = 3.81;
    int bLimba = 2.94;
    int bPile = 4.32;
    int wSpray = 3.82;
    int shattered = 3.25;
    int demeter = 3.58;
    int bWater = 3.46;
    int zirka = 13.80;
    int graven = 15.37;
    int overgrowth = 38.61;
    int eDragon = 75.00;
    int oFoam = 35.20;
    int graphite = 33.20;
    int gKoi = 10.21;
    int fSerpent = 287.18;
    char name[50];
    int YN;
    int y = 1;
    int n = 0;
    int mSpent = 0;
    int mEarned = 0;

    std::cout << "Welcome to TheM80's Case Opening Simulator!";
    std::cout << "\nWhat's your name? ";
    cin.getline(name, 50);
    retry:
    system("cls");
    std::cout << "Money Spent: "<<  mSpent << endl;
    std::cout << "Money Earned: " << mEarned << endl;
    std::cout << "Would you like to open a case, " << name << "?" << endl;
    std::cout << "Enter 1 for yes or 2 for no! ";
    std::cin >> YN;

    if (YN == 1)
    {
        mSpent + 11.40;
        std::cout << "Spinning... ";
        Sleep(3000);

        int gWeapon;
        srand( time(0));
        gWeapon=rand()%100+1;
        int gWeaponGen = gWeapon;
        if(gWeaponGen > 0 && gWeaponGen < 8)
        {
            std::cout << "You're weapon is... ";
            Sleep(1200);
            std::cout << "Nova Tempest! ";
            mEarned + 3.81;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 8 && gWeaponGen < 15)
        {
            std::cout << "You're weapon is... ";
            Sleep(1700);
            std::cout << "Dual Berettas Black Limba! ";
            mEarned + 2.94;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 15 && gWeaponGen < 22)
        {
            std::cout << "You're weapon is... ";
            Sleep(1000);
            std::cout << "UMP-45 Bone Pile! ";
            mEarned + 4.32;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 22 && gWeaponGen < 29)
        {
            std::cout << "You're weapon is... ";
            Sleep(1500);
            std:cout << "SG 553 Wave Spray! ";
            mEarned + 3.82;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 29 && gWeaponGen < 36)
        {
            std::cout << "You're weapon is... ";
            Sleep(1400);
            std::cout << "Galil AR Shattered! ";
            mEarned + 3.25;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 36 && gWeaponGen < 40)
        {
            std::cout << "You're weapon is... ";
            Sleep(1450);
            std::cout << "G3SG1 Demeter! ";
            mEarned + 3.58;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 43 && gWeaponGen < 51)
        {
            std::cout << "You're weapon is... ";
            Sleep(1800);
            std::cout << "M4A1-S Bright Water! ";
            mEarned + 3.46;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 51 && gWeaponGen < 59)
        {
            std::cout << "You're weapon is... ";
            Sleep(1800);
            std::cout << "M4A4 Zirka! ";
            mEarned + 13.80;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 59 && gWeaponGen < 67)
        {
            std::cout << "You're weapon is... ";
            Sleep(1800);
            std::cout << "MAC-10 Graven! ";
            mEarned + 15.37;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 67 && gWeaponGen < 75)
        {
            std::cout << "You're weapon is... ";
            Sleep(1800);
            std::cout << "USP-S Overgrowth! ";
            mEarned + 38.61;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 75 && gWeaponGen < 82)
        {
            std::cout << "You're weapon is... ";
            Sleep(2000);
            std::cout << "P90 Emerald Dragon! ";
            mEarned + 75.00;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 82 && gWeaponGen < 89)
        {
            std::cout << "You're weapon is... ";
            Sleep(2000);
            std::cout << "P2000 Ocean Foam! ";
            mEarned + 35.20;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 89 && gWeaponGen < 95)
        {
            std::cout << "You're weapon is... ";
            Sleep(2000);
            std::cout << "AWP Graphite! ";
            mEarned + 33.20;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 95 && gWeaponGen < 98)
        {
            std::cout << "You're weapon is... ";
            Sleep(2500);
            std::cout << "Desert Eagle Golden Koi! ";
            mEarned + 10.21;
            system("pause");
            goto retry;
        }
        else if(gWeaponGen > 98 && gWeaponGen < 99)
        {
            std::cout << "You're weapon is... ";
            Sleep(3000);
            std::cout << "Stattrak AK-47 Fire Serpent! Congratulations! ";
            mEarned + 5769.00;
            system("pause");
            goto retry;
        }

    return 0;
    }
}
.
If you just bother to read the warnings...
mEarned + 5769.00; and similar would not modify the variable. You are adding two things and doing nothing with the result, you need to assign it somewhere
For example mEarned = mEarned + 5769.00;, which may be condensed as mEarned += 5769.00;


Apart.
- Please DOA (don't ever abbreviate). You can easily write money_earned.
- Try to minimize your testcase. `Sleep(1200)' has no relation with your issue (and it's an awful interface design choice, but that's another mater). Same for `system()' and whatever you are using windows.h and dos.h for.
- If your testcase needs user input, then you ought to provide an input example.
I'm sorry that there were so many glaring flaws but I'm new to C++ and programming as a whole so everything I know is taken from a dozen different tutorials and a dozen random threads with solutions to issues I've experienced. The reason I have 'Sleep' used commonly is due to this program trying to replicate opening a case in CS which can take anywhere from 4 seconds to 10 seconds so I figured it would be alright to add similar delay.
Line 15-29: All these fractional values are going to be truncated. ints can not store decimal places. Use doubles if you if the fractional part is significant.

Line 40: gotos are evil. Use a loop instead. It may look simple now, but as your program gets more complicated, gotos are hard to debug and do not give structure to your program.

Line 55: Do not call srand() within a loop or a random number function. srand() sets the RNG to a particular starting point. Calling srand() repeatedly can cause the RNG to return the same random numbers. srand() should be called ONCE at the beginning of main().
http://www.cplusplus.com/reference/cstdlib/srand/

Line 63,72,81,90,99,108,117,126,135,144,153,162,171,180,189: As ne555 said these lines do nothing.

Line 58,67,76,etc: Your if statements have holes in them. What if gWeaponGen is exactly 8, 15, 22 etc?

Line 52,61,70,etc: I personally hate any game that forces delays. What value does that add to the game? Those delays are longer than my attention span.
I switched the variable type to double, since the program is nearly completed I don't feel the need to replace the gotos with loops since the program won't be getting anymore complicated although rest assured I do know how to do it. I fixed the lines that do nothing and they are functioning properly and I patched up the if statements to remove the holes. I shortened the delays significantly but since it's trying to simulate something already done that does have the delays I voted to keep them in only shorter. Thank you for your suggestions.
Even if you keep the goto, there's no need to repeat it in every if-else block. You could have just the one goto after all the if-elses.

Same with the system("pause");

Andy

Also, the last if test looks impossible - if(gWeaponGen > 98 && gWeaponGen < 99)

98 is not greater than 98, but it is less that 99 => evaluates to false.
99 is greater than 98 nut not less than 99 => evaluates to false for 99.
Topic archived. No new replies allowed.