.exe runtime error

Can't figure out why I am getting runtime error. After showing below results a window robotrally.exe shows up

And says robotrally.exe has stopped working, windows is checking for solutions for the problem

I am using NetBeans IDE 7.4. Operating system Windows 8


Welcome to Testing Robot Rally Game

Building robot...
Check robot heading      : NORTH
Check robot health       : 6
Test Robot build   

Test-one



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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

//robot.h
 
#ifndef ROBOT_H
#define	ROBOT_H

#include<string>

enum Rotate{RIGHT, LEFT, UTURN}; 
enum Direction{NORTH, SOUTH, EAST, WEST}; 

class Robot{
   
private:
    int _health; 
    Direction _heading; 
    bool decrementalHealth();
    
public:
    Robot();
    Robot(int health, Direction face);
    ~Robot();
    std::string getHeading();
    int getHealth() const;
    void setHeading(Direction);
    int decrementalHealth(int);
    void rotate(Rotate);
    std::string toString();
    
};

#endif	/* ROBOT_H */

/**************************************************************/

//robot.cpp
#include"robot.h" 
#include<iostream> 
#include<string>
#include<sstream>
using namespace std;

 Robot::Robot()
 {
    _health = 6;  
    _heading = NORTH;
 }
 
 Robot::Robot(int health,Direction face)
 {
     _health = health;
     
      if(_health>6||_health<0){ 
         _health=6;
         }
     _heading = face; 
 }
 
 Robot::~Robot(){
 
 }
 
 string Robot::getHeading(){
    return toString();
 }
 
 int Robot::getHealth() const{
     return _health;
 }
 
 void Robot::setHeading(Direction face)
 {
     _heading = face;
 }
     
void Robot::rotate(Rotate turn)
 {  
      Direction old_heading = _heading; 
switch(turn) {  
case NORTH:
 
        switch(_heading){
        case NORTH:
            _heading=WEST;
        break;
            
        case SOUTH:
            _heading=EAST;
        break;
        
        case EAST:
            _heading=NORTH;
        break;
        
        case WEST:
            _heading=SOUTH;
        break;
       }
    break;
   }
}

case RIGHT: 
        switch(_heading){
        case NORTH:
            _heading=EAST;
        break;
            
        case SOUTH:
            _heading=WEST;
        break;
        
        case EAST:
            _heading=SOUTH;
        break;
        
        case WEST:
            _heading=NORTH;
        break;
    }
break;

case UTURN: 
        switch(_heading){
        case NORTH:
            _heading=SOUTH;
        break;
            
        case SOUTH:
            _heading=NORTH;
        break;
        
        case EAST:
            _heading=WEST;
        break;
        
        case WEST:
            _heading=EAST;
        break;
    }
break;
 }

if(old_heading!=_heading){
     return true; 
    }
 return false;
}
 
 bool Robot::decrementalHealth()
 {
     if(_health<6||_health>0)
     {
         return true;
     }
     else if(_health<=0)  
     {
         _health=0;  
         return false;
     }
 }
 

 int Robot::decrementalHealth(int amount)
 {
     _health = _health - amount; 
     decrementalHealth(); 
     return _health;
 }
    
 string Robot::toString()
 {
     string direction_string[] = {"NORTH", "SOUTH", "EAST", "WEST"}; 
     return direction_string[_heading];
 }


/*********************************************************/

//test.h
#ifndef TEST_H
#define	TEST_H

#include"robot.h"
#include<vector>

class Test{
    
private:
    Robot *_testRobot; 
   
public:
    int main();
    void buildRobot();

    void testOne();
   
    void testTwo();
};

#endif	/* TEST_H */

/********************************************************/

//test.cpp
#include "test.h"
#include "iostream"
using namespace std;

int main(){
    
    Test s; 
    s.testOne();  
    return 0;
}

void Test::buildRobot(){
cout<<"Welcome to Testing Robot Rally Game\n\n";

cout<<"Building robot...\n"; 

        Robot *_one = new Robot(6,NORTH);  north
        cout<<"Check robot heading     :    "<<_one->getHeading()<<endl;
        cout<<"Check robot health      :    "<<_one->getHealth()<<endl;
        cout<<"Test Robot build\n";}
     }
void Test::testOne(){
    buildRobot(); 
    cout<<"\nTest-One\n";

    cout<<"New direction: "<<_testRobot->getHeading()<<endl;
    delete _testRobot;
   }
How is it even possible that you're compiling this?
Sorry I have just started c++. Why? What's wrong?
On line 101 you have an excessive closing brace ( } )
On line 222, you a random undeclared identifier "north" do nothing
On line 226, you have another excessive closing brace
On lines 80 and 103 you are mixing different kinds of enumerated types within a switch control structure.
Another excessive closing brace at line 142.
As well as some other things.
Are you sure this is the actual code?
Last edited on
Topic archived. No new replies allowed.