Help. Abort() has been called

Write your question here.
Hi. I need pointers on what could be wrong with my damage calculations. everything compiles and runs good aside from the damage calculations

Whenever I run it, it says abort() has been called
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
////////////////////////////
//////"pokemon.cpp"/////////
////////////////////////////
#include "pokemon.h"
#include <iostream>
#include <string>
using namespace std;


Pokemon::Pokemon(string name, int num, Type type1){
	this->_name = name;
	this->_ndex = num;
	this->types[0] = type1;
	this->type_count = 1;
}

Pokemon::Pokemon(string name, int num, Type type1, Type type2){
	this->_name = name;
	this->_ndex = num;
	this->types[0] = type1;
	this->types[1] = type2;
	this->type_count = 2;
}

string Pokemon::name(){
	return _name;
}

int Pokemon::Ndex(){
	return _ndex;
}

Pokemon::Type Pokemon::type1(){

	return types[0];
}

bool Pokemon::is_multitype(){
	if(type_count == 1)
		return false;
	else
		return true;
}

Pokemon::Type Pokemon::type2(){
return types[1];
cout << types[1];
}

float Pokemon::damage_multiplier(Type attack_type){
	float dmg;
	Type t1 = types[0];
	if(t1 = Normal){
		
		switch(attack_type){
			case Normal:
				dmg = 1.0;
				return dmg;
				break;
			case Fighting:
				dmg = 2.0;
				return dmg;
				break;
			case Flying:
				dmg = 1.0;
				return dmg;
				break;
			case Poison:
				dmg = 1.0;
				return dmg;
				break;
	}
	}
	if(t1 = Fighting){
		switch(attack_type){
			case Normal:
				dmg = 1.0f;
				return dmg;
				break;
			case Fighting:
				dmg = 1.0;
				return dmg;
				break;
			case Flying:
				dmg = 2.0;
				return dmg;
				break;
			case Poison:
				dmg = 1.0;
				return dmg;
				break;
	}
	}
		if(t1 = Flying){
		switch(attack_type){
			case Normal:
				dmg = 1.0;
				return dmg;
				break;
			case Fighting:
				dmg = 0.5;
				return dmg;
				break;
			case Flying:
				dmg = 1.0;
				return dmg;
				break;
			case Poison:
				dmg = 1.0;
				return dmg;
				break;
	}
	}
		if(t1 = Poison){
		switch(attack_type){
			case Normal:
				dmg = 1.0;
				return dmg;
				break;
			case Fighting:
				dmg = 0.5;
				return dmg;
				break;
			case Flying:
				dmg = 1.0;
				return dmg;
				break;
			case Poison:
				dmg = 0.5;
				return dmg;
				break;
	}
	}
	return 1;
}


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
///////////////////////////////
///////////"main.cpp"//////////
///////////////////////////////
#include <cstdlib>
#include <iostream>
#include "pokemon.h"

using namespace std;


inline void _test(const char* expression, const char* file, int line)
{
	cerr << "test(" << expression << ") failed in file " << file << ", line " << line << "." << endl;
        abort();
}

#define test(EXPRESSION) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__))


int main()
{
	// Create a bunch of pokemon objects. 
	// (Data taken from the official list, plz don't sue me The Pokemon Company)
	Pokemon bouffalant("Bouffalant", 626, Pokemon::Normal);
	Pokemon cinccino("Cinccino", 573, Pokemon::Normal);
	Pokemon garbodor("Garbodor", 569, Pokemon::Poison);
	Pokemon mankey("Mankey", 56, Pokemon::Fighting);
	Pokemon tornadus("Tornadus", 641, Pokemon::Flying);

	Pokemon pidgey("Pidgey", 16, Pokemon::Normal, Pokemon::Flying);
	Pokemon fletchling("Fletchling", 661, Pokemon::Normal, Pokemon::Flying);
	Pokemon zubat("Zubat", 41, Pokemon::Poison, Pokemon::Flying);
	Pokemon toxicroak("Toxicroak", 454, Pokemon::Poison, Pokemon::Fighting);
	Pokemon hawlucha("Hawlucha", 701, Pokemon::Fighting, Pokemon::Flying);


	// Test name()	
	test(bouffalant.name() == "Bouffalant");
	test(cinccino.name() == "Cinccino");
	test(garbodor.name() == "Garbodor");
	test(mankey.name() == "Mankey");
	test(tornadus.name() == "Tornadus");
	test(pidgey.name() == "Pidgey");
	test(fletchling.name() == "Fletchling");
	test(zubat.name() == "Zubat");
	test(toxicroak.name() == "Toxicroak");
	test(hawlucha.name() == "Hawlucha");
	

	// Test Ndex()	
	test(bouffalant.Ndex() == 626);
	test(cinccino.Ndex() == 573);
	test(garbodor.Ndex() == 569);
	test(mankey.Ndex() == 56);
	test(tornadus.Ndex() == 641);

	test(pidgey.Ndex() == 16);
	test(fletchling.Ndex() == 661);
	test(zubat.Ndex() == 41);
	test(toxicroak.Ndex() == 454);
	test(hawlucha.Ndex() == 701);


	// Test is_multitype()
	test(!bouffalant.is_multitype());	
	test(!cinccino.is_multitype());	
	test(!garbodor.is_multitype());	
	test(!mankey.is_multitype());	
	test(!tornadus.is_multitype());	

	test(pidgey.is_multitype());	
	test(fletchling.is_multitype());	
	test(zubat.is_multitype());	
	test(toxicroak.is_multitype());	
	test(hawlucha.is_multitype());	

	
	// Test type1()
	test(bouffalant.type1() == Pokemon::Normal);
	test(cinccino.type1() == Pokemon::Normal);
	test(garbodor.type1() == Pokemon::Poison);
	test(mankey.type1() == Pokemon::Fighting);
	test(tornadus.type1() == Pokemon::Flying);

	test(pidgey.type1() == Pokemon::Normal);
	test(fletchling.type1() == Pokemon::Normal);	
	test(zubat.type1() == Pokemon::Poison);	
	test(toxicroak.type1() == Pokemon::Poison);	
	test(hawlucha.type1() == Pokemon::Fighting);	


	// Test type2()
	test(pidgey.type2() == Pokemon::Flying);
	test(fletchling.type2() == Pokemon::Flying);	
	test(zubat.type2() == Pokemon::Flying);	
	test(toxicroak.type2() == Pokemon::Fighting);	
	test(hawlucha.type2() == Pokemon::Flying);	

	

	// Test damage_multiplier() for single-type Pokemon
	test(bouffalant.damage_multiplier(Pokemon::Normal) == 1.0f);	
	test(bouffalant.damage_multiplier(Pokemon::Fighting) == 2.0f);	
	test(bouffalant.damage_multiplier(Pokemon::Flying) == 1.0f);	
	test(bouffalant.damage_multiplier(Pokemon::Poison) == 1.0f);	
	
	test(garbodor.damage_multiplier(Pokemon::Normal) == 1.0f);	
	test(garbodor.damage_multiplier(Pokemon::Fighting) == 0.5f);	
	test(garbodor.damage_multiplier(Pokemon::Flying) == 1.0f);	
	test(garbodor.damage_multiplier(Pokemon::Poison) == 0.5f);	
	
	test(mankey.damage_multiplier(Pokemon::Normal) == 1.0f);	
	test(mankey.damage_multiplier(Pokemon::Fighting) == 1.0f);	
	test(mankey.damage_multiplier(Pokemon::Flying) == 2.0f);	
	test(mankey.damage_multiplier(Pokemon::Poison) == 1.0f);	

	test(tornadus.damage_multiplier(Pokemon::Normal) == 1.0f);	
	test(tornadus.damage_multiplier(Pokemon::Fighting) == 0.5f);
	test(tornadus.damage_multiplier(Pokemon::Flying) == 1.0f);	
	test(tornadus.damage_multiplier(Pokemon::Poison) == 1.0f);	
	
	cout << "complete." << endl;
}


Last edited on
= is used for assigning values. If you want to compare equality you should use == instead.
Topic archived. No new replies allowed.