Subtraction problem

Hello im trying to make a simple text rpg game and so far i have a problem that couldnt find an alternative solution. The result of a subtraction is not correct and its just random big numbers.
Sorry i have to copy the whole program im a noob and i dont know what is wrong
i point where is the problem with //

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
  #include <cstdlib>
#include <iostream>
#include <ctime>


using namespace std;
int strength=1;
int dexterity=1;
int perception=1;
int intelligence=1;
int charisma=1;
int stamina=1;
int health;
int melle=strength+dexterity;
int ranged=strength+perception;
int force=strength+intelligence;
int intmidate=strength+charisma;
int heavy=strength+stamina;
int mobility=dexterity+perception;
int disarm=dexterity+intelligence;
int bluff=dexterity+charisma;
int light=dexterity+stamina;
int senses=perception+intelligence;
int haggle=perception+charisma;
int instinct=perception+stamina;
int persuasion=intelligence+charisma;
int survival=intelligence+stamina;
int leadership=charisma+stamina;
int start=0;
string name;



void stats()
{


    int st=strength;
    int de=dexterity;
    int pe=perception;
    int in=intelligence;
    int ch=charisma;
    int sa=stamina;
    int total2=st+de+pe+in+ch+sa;
    int total1;
    total1-=total2; //This is the subtraction
    if (start==0)
    {
       char x;
        do{
        cout<<"What is your name?"<<endl;
        cin>>name;
     cout<<"Are you sure that "<<name<<" is your name? (Press Y to confirm)"<<endl;
     cin>>x;
     system("cls");
    }while (x!='Y');
   int v=0;
   do{
        string y;
        cout<<name<<" you have "<<total1<<" remaining stat points to put at your atribbutes."<<endl; //Here is the bug i get random numbers instead of the actual result of the Subtraction
        cout<<"Remember it's skills that matter most not atributes."<<endl;
        cout<<"(Type the atribute you want to increase (Min 1 - Max 10)"<<endl;
        cout<<"-----------------------------------------------"<<endl;
        cout<<"strength= "<<strength<<" ('str' for description)"<<endl;
        cout<<"dexterity= "<<dexterity<<" ('dex' for description)"<<endl;
        cout<<"perception= "<<perception<<" ('per' for description)"<<endl;
        cout<<"intelligence= "<<intelligence<<" ('int' for description)"<<endl;
        cout<<"charisma= "<<charisma<<" ('cha' for description)"<<endl;
        cout<<"stamina= "<<stamina<<" ('int' for description)"<<endl;

cin>>y;
if (y=="strength")
{
    do{
        system("cls");
        cout<<"Choose how much strength you will have"<<endl;
        cin>>strength;
        st=strength;
    }while (strength<1 or strength>10);
}
if (y=="dexterity")
{
    do{
        system("cls");
        cout<<"Choose how much dexterity you will have"<<endl;
        cin>>dexterity;
        de=dexterity;
    }while (dexterity<1 or dexterity>10);
}
if (y=="perception")
{
    do{
        system("cls");
        cout<<"Choose how much perception you will have"<<endl;
        cin>>perception;
        pe=perception;
    }while (perception<1 or perception>10);
}
if (y=="intelligence")
    do{
        system("cls");
        cout<<"Choose how much intelligence you will have"<<endl;
        cin>>intelligence;
        in=intelligence;
    }while (intelligence<1 or intelligence>10);
if (y=="charisma")
{
    do{
        system("cls");
        cout<<"Choose how much charisma you will have"<<endl;
        cin>>charisma;
        ch=charisma;
    }while (charisma<1 or charisma>10);
}
if (y=="stamina")
{
     do{
        system("cls");
        cout<<"Choose how much stamina you will have"<<endl;
        cin>>stamina;
        sa=stamina;
    }while (stamina<1 or stamina>10);
}

if (total1==0)
{
    cout<<"END"<<endl;
    if (y=="END")
    {
        v=1;
    }
    }
        total2=st+de+pe+in+ch+sa;
        total1-=total2; //same subtraction
system("cls");
   }while (v<1);

}
}


int main()
{
stats();
}
Last edited on
You are using total1 without having given it a value first; so it is a random (probably very large negative or positive) number.
oh god how did i miss that i should get some sleep..
thank you very much for your help Zhuge
No problem.

Also, if you turn on all warnings for your compiler, you can have it let you know about things like this.
Topic archived. No new replies allowed.