Not sure why my code has no output

Hello, I'm trying to create a novel program to take lines from a filestream as parameters to create random objects. My code as below:

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
  #include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "monster.h"
using namespace std;
	
void createMonster(string weather, string humid, string tide, int count);
	
int main() {
	
	string weather;
	string humid;
	string tide;
	int count = 0;
	
	ifstream input;
	input.open("conditions.txt");
	
	Monster* mon[100];
	
	string line;
	
	while(!input.eof()) {
		getline(input,line);
		stringstream ss(line);
		ss >> weather >> humid >> tide;
		void createMonster(string weather, string humid, string tide, int count);
		++count;
	}
	
	for (int i=0;i<count;i++) { // not sure why this isn't giving any output
		mon[i]->attack();
	}
}

void createMonster(string weather, string humid, string tide, int count, Monster* mon[100]) {
	
	if (weather=="rainy") {
		if (humid=="low") {
			if (tide=="low") {
				mon[count] = new Cat(weather, humid, tide);
			}
			else {
				mon[count] = new Pidgeon(weather, humid, tide);
			}
		}
		else {
			if (tide=="low") {
				mon[count] = new Horse(weather, humid, tide);
			}
			else {
				mon[count] = new Rat(weather, humid, tide);
			}
		}
	}
	else if(weather=="thunder") {
		if (humid=="low") {
			if (tide=="low") {
				mon[count] = new Dog(weather, humid, tide);
			}
			else {
				mon[count] = new Fish(weather, humid, tide);
			}
		}
		else {
			if (tide=="low") {
				mon[count] = new Hamster(weather, humid, tide);
			}
			else {
				mon[count] = new Snake(weather, humid, tide);
			}
		}
	}
	else if(weather=="shower") {
		if (humid=="low") {
			if (tide=="low") {
				mon[count] = new Tiger(weather, humid, tide);
			}
			else {
				mon[count] = new Goat(weather, humid, tide);
			}
		}
		else {
			if (tide=="low") {
				mon[count] = new Wolf(weather, humid, tide);
			}
			else {
				mon[count] = new Rabbit(weather, humid, tide);
			}
		}
	}
}


Here's part of my header file (all the derived classes are more or less the same):

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

class Monster {
public:
	Monster(string _weather, string _humid, string _tide);

	string getWeather() {return mWeather;}
	string getHumid() {return mHumid;}
	string getTide() {return mTide;}
	
	virtual void attack() = 0;
	


private:
	string mWeather;
	string mHumid;
	string mTide;
};

Monster::Monster(string _weather, string _humid, string _tide):mWeather(_weather),mHumid(_humid),mTide(_tide) {}
	
class Cat: public Monster {
public:
	Cat(string _weather, string _humid, string _tide): Monster(_weather,_humid,_tide) {}
		
	void attack() {cout << "Cat scratch!" << endl;}
};

class Pidgeon: public Monster {
public:
	Pidgeon(string _weather, string _humid, string _tide): Monster(_weather,_humid,_tide) {}
		
	void attack() {cout << "Pidgeon divebomb!" << endl;}
};

// more derived classes etc. etc 


An example of my input file:

1
2
3
4
rainy low low
thunder high low
shower high high
shower low high


When compiled my program doesn't return any errors, but when I run the code I'm not getting the expected output (which is for each of the created Monsters to "attack"). I've tried outputting statements before and after the attack for loop, statements placed before the for loop will print however trying to output a statement after won't happen. I'm wondering if the issue is to do with inefficient code?
Line 28 is a function declaration. If you want to call the function you need to leave out the return type and the type of the arguments.

 
createMonster(weather, humid, tide, count, mon);
Last edited on
Oh.

I corrected that and fixed the function prototype (missed out "Monster* mon[]" as argument). Also noticed I had specified the array length in the function declaration so I corrected that:

 
void createMonster(string weather, string humid, string tide, int count, Monster* mon[]) {


When I run it now, I get the "Error while launching: the system cannot find the file specified" message. Looking online seems to tell I have an error in the way I've written my code, could I have called my array arguments incorrectly?
Topic archived. No new replies allowed.