Coversion Errors

I am getting these areas inside of the switch when I make a case and I cant figure out a solution. Any help would be much appreciated.

error: invalid conversion from 'const char*' to 'int' [-fpermissive]
error: '(int)((long int)"1")' is not a constant expression

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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//James Wester
//The Last Frontier

#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int main()
{
    char direction;
    char enterRoom;
    float playerHealth, playerMaxhealth;
    float enemyHealth, enemyMaxhealth;
    float biteDamage, punchDamage, kickDamage;
    float biteChance, punchChance, kickChance;
    float randomChance, enemyRandomchance;
    int enemyAttackchoice;
    float enemyFeralhealth, enemyMaxferalhealth;
    string enemyAttack;
    string fightCommand;
    string name;
    string pickupAxe;
    cout << "Welcome to The Last Frontier, enter your character's name to begin: ";
    cin >> name;
    
    crashscene:
    
    cout << name << ", it is October, 1973. You have been involved in an automobile accident." << endl;
    cout << "You are low on supplies and need to find shelter immediately to protect yourself from the harsh climates" << endl;
    cout << "of Barrow, Alaska." << endl;
    cout << "Your vehicle is totaled; you are on foot." << endl; 
    cout << "Enter whether to go north, go south, go east, go west." << endl;
    cout << "(n = go north, s = go south, e = go east, and w = go west): ";
    cin >> direction;
    
    biteDamage = 20;
    kickDamage = 10;
    punchDamage = 5;
    
    biteChance = 35;
    kickChance = 60;
    punchChance = 80;
    
    playerMaxhealth = 30;
    playerHealth = 30;
    
    enemyFeralhealth = 40;
    enemyMaxferalhealth = 40;
    
    
    
    if (direction == 'n')
    {
        generalstore:
        
        cout << "Heading north you find a small gas station with a general store." << endl;
        cout << "The store seems to have been there for over forty years, with aged oak" << endl;
        cout << "which when new was used to construct the bulding." << endl;
        cout << "(press f then press enter to enter the General Store or b to go back): ";
        cin >> enterRoom;
        
        
        if (enterRoom == 'f')
        {   
            string pickupAxe;
            cout << "The General store appears to be completely abandoned and" << endl;
            cout << "You see a dead body on the ground covered in flannel." << endl;
            cout << "You notice something of importance on the ground," << endl;
            cout << "would you like to pick it up? (Press and enter p to pickup the item or" << endl;
            cout << "press b and enter to leave): ";
            cin >> pickupAxe;
                
        
        
            if (pickupAxe == "p")
            {
                cout << "You have found a hefty Axe. Surely this will be useful at some point." << endl;
                punchDamage = 25;    
            }
    
            if (pickupAxe == "b")
            {
                cout << "You chose not to pick up the item and you leave the store." << endl;
                punchDamage = 5;
                goto generalstore;
            }
        }
        
        if (enterRoom == 'b')
        {
            goto crashscene;
        }
        return 0;
    }
    
   
    
    if (direction == 'e')
    {
        cout << "Going east you find an array of small cabins." << endl;
        cout << "Two of the Cabins have been broken into, one on the left and" << endl;
        cout << "one on the right." << endl;
        cout << "(Press f then enter to enter the Cabin on the right)" << endl;
        cout << "(Or press g then enter to enter the cabin on the right): "; 
        
        cin >> enterRoom;
        
        if (enterRoom == 'f')
        {
            cout << "Upon entering the cabin you discover a human gone feral!" << endl; 
            cout << "Unfortunately the human cannot be negotiated with, you must" << endl;
            cout << "fight to survive!";
            cout << "Fighting Commands are: punch, kick, bite: ";
            
            cin >> fightCommand;
            
            while (enemyFeralhealth > 0 && playerHealth > 0)
            {
                cout << "Feral Human's Health: " << enemyFeralhealth << "/" << enemyMaxferalhealth << endl;
                cout << "Your health: " << playerHealth << "/" << playerMaxhealth << endl;
                cin >> fightCommand;
                
                if (fightCommand == "punch")
                {
                    randomChance = rand() % 100 + 1;
                    if (randomChance >= punchChance)
                    {
                        enemyFeralhealth -= punchDamage;
                    }
                }
                
                
                if (fightCommand == "kick")
                {
                    randomChance = rand() % 100 + 1;
                    if (randomChance >= kickChance)
                    {
                        enemyFeralhealth -= kickDamage;
                    }
                    
                }
                
                if (fightCommand == "bite")
                {
                    randomChance = rand() % 100 + 1;
                    if (randomChance >= biteChance)
                    {
                        enemyFeralhealth -= biteDamage;   
                    }
                
                }
                
                enemyRandomchance = rand() % 100 + 1;    
                enemyAttackchoice = rand() & 3 + 1;
                switch(enemyAttackchoice)
                {
                    case "1": {
                    
                        enemyAttack = "punch";
                        break;
                    
                    
                    case "2":
                    
                        enemyAttack = "kick";
                        break;
                    
                    
                    case "3":
                    
                        enemyAttack = "bite";
                        break;
                    }
                                
                }                
                
                if (fightCommand == "punch")
                {
                    if (enemyRandomchance >= punchChance)   
                    {
                        playerHealth -= punchDamage;
                    }
            
                }    
                
                else if (fightCommand == "kick")
                {
                    if (enemyRandomchance >= kickChance)
                    {
                        playerHealth -= kickDamage;
                    }
                
                }
                
                else if (fightCommand == "bite")
                {
                    if (enemyRandomchance >= biteChance)
                    {
                        playerHealth -= biteDamage;
                    }
                        
                }
                
            }
            
            
        }
        
        return 0;
    }
    
  
    
    return 0;
}

Remove the quotes in lines 159, 165, 171. Your case is an int.
Which is exactly what your compiler told you.


I presume that your line 156
enemyAttackchoice = rand() & 3 + 1;
was intended to be
enemyAttackchoice = rand() % 3 + 1;

You are also redefining pickupAxe on line 67, which will hide the variable defined on line 24.

Turn your error checking up on your compiler (or you can use C++ shell and do so through the compiler options). There are one or two other warnings that you may need to consider.
Last edited on
Okay thanks, I will try doing those solutions.
Last edited on
Thank you very much, the solutions have worked flawlessly!
Topic archived. No new replies allowed.