C++ Text Based RPG code HELP!

Hello Everyone! This is my first post on this forums. I would really like someone to tell me what the hell is wrong. This is just a starting TEXT RPG game
and it compiled and ran before perfectly fine but now it show's an Int Function error on the underlinedcode down below. I'm positive it's correct because it did compile before. Is this some error?

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
  #include <iostream>
#include <string>
using namespace std;

int main()
{
  string name;
 int age;
 string gender;
 string Continue;
 string sex;
 
 char userName[100];

    cout <<" Please select a Username: ";
    cin >>userName;

    cout <<"Welcome: "<<userName<<endl;
 cout << "" << endl;
 cout << "Welcome\n" << endl;
 cout << userName;
 cout << ", Welcome to Lands of Magnolia!\n" << endl;
 cout << "..." << endl;
 cout << " " << endl;
 cout << "What is your character's age?\n" << endl;
 cin >> age;
 cout << "..." << endl;
 cout << " " << endl;
 cout << "What is your character's gender?:\n" << endl;
 cin >> gender;
 cout << "..." << endl;
 cout << "" << endl;
 cout << "Enter 'Continue' to continue. Then you can choose a class!\n" << endl;
 cin >> Continue;
 
 cout << "..." << endl;

 cout << "Welcome to the Lands of Magnolia! First, you must choose a class!\n" << endl;
 cout << "(1)\n" << endl;
 cout << "The Warrior:\n" << endl;
  cout << "Attack: 60" << endl;
   cout << "Defence: 50" << endl;
    cout << "Magic: 10" << endl;
     cout << "Speed: 30" << endl;
      cout << "Starting Weapon: Longsword." << endl;
      
 cout << "..." << endl;
 
 cout << "(2)\n" << endl;
 cout << "The Wizard:\n" << endl;
  cout << "Attack: 20" << endl;
   cout << "Defence: 30" << endl;
    cout << "Magic: 80" << endl;
     cout << "Speed: 20" << endl;
      cout << "Starting Weapon: Oak Staff." << endl;
      
       cout << "..." << endl;
       
        cout << "(3)\n" << endl;
       cout << "The Knight:\n" << endl;
       cout << "Attack: 50" << endl;
       cout << "Defence: 70" << endl;
       cout << "Magic: 20" << endl;
       cout << "Speed: 10" << endl;
        cout << "Starting Weapon: Battleaxe." << endl;
        
        cout << "..." << endl;
               
                   cout << "(4)\n" << endl;  
      cout << "The Assassin:\n" << endl;
        cout << "Attack: 40" << endl;
        cout << "Defence: 20" << endl;
        cout << "Magic: 10" << endl;
        cout << "Speed: 80" << endl;
        cout << "Starting Weapon: Wicked Dirk." << endl;
        
        cout << "..." << endl;
         
          cout << "(5)\n" << endl;
         cout << "The Wanderer" << endl;
         cout << "Attack: 40" << endl;
         cout << "Defence: 40" << endl;
         cout << "Magic: 35" << endl;
         cout << "Speed: 35" << endl;
         cout << "Starting Weapon: Wooden Stick." << endl;
         
         cout << "-----" << endl;
         
      int selection;
      cout << "Please Enter the Number (eg. 1, 2) not the name of the class to select\n " << endl;
      cin >> selection;
      if (selection == 1);
      cout << "You chose the Warrior class!\n" << endl;
      cout << "..." << endl;
      cout << "" << endl;
      else if (selection == 2)
      cout << "You chose the Wizard class!\n" << endl;
      cout << "..." << endl;
      cout << "" << endl;
      else if (selection == 3)
      cout << "You chose the Knight class!\n" << endl;
      cout << "..." << endl;
      cout << "" << endl;
      else if (selection == 4)
      cout << "You chose the Assassin class!\n" << endl;
      cout << "..." << endl;
      cout << "" << endl;
      else if (selection == 5)
      cout << "You chose the Wanderer class!\n" << endl;
      cout << "..." << endl;
      cout << "" << endl;
     
      cout << "-----" << endl;
      
 string Ok;
 cout << " Please enter the letter 'Ok' to continue.\n" << endl;
 cin >> Ok;
 
 
 
 cin.get();
 return 0;
}
Last edited on
Only the statement after if (condition) is part of the if statement.

On line 92 you have a semicolon right after so the semicolon creates an empty statement (a statement that doesn't do anything) so none of the lines that follows will be part of the if statement.

If you remove the semicolon from line 92 then the following statement is on line 93. If you want all the lines 93-95 to be part of the if statement you will have to create a compound statement by using { and }.
1
2
3
4
5
6
if (selection == 1)
{
	cout << "You chose the Warrior class!\n" << endl;
	cout << "..." << endl;
	cout << "" << endl;
}
Hi @Wulfinite,
try deleting the semicolon at
the end of this line (92)
if (selection == 1); //<<<
Thanks guys :) I removed the semicolon at the end of line 92 and added the braces. It now works perfectly. Thank you again.
Topic archived. No new replies allowed.