Ogres vs Dwarfs help!?

closed account (iNU7ko23)
Hi this is my code but unfortunately it just isn't working. So, if you could tell me a error I made or bug in the program that would be greatly appreciated!

#include <iostream>
#include <string>
#include <cstdlib>

using std::cout;
using std::cin;
using namespace::std;

bool intro();

char fight(void);

int speed = rand();

int strength = rand();

int number = rand();

int speed1 = rand();

int strength1 = rand();

int number1 = rand();

int round = 0;

bool answer = false;

int main()
{
cout << "The Dwarfs and Ogers are about to fight for three rounds!\n";
cout << "Are you ready to fight! y or n";
cin >> answer;
if(intro(void))
for(round = 0; round < 3; round++;)
{
cout << "Here are the stats...\n";
cout << "DWARFS\n";
cout << "speed = \n" << speed;
cout << "strength = \n" << strength;
cout << "number = \n" << number;
cout << "OGRES\n";
cout << "speed = \n" << speed1;
cout << "strength = \n" << strength1;
cout << "number = \n" << number1;
char fight()
cout << "The winner is " winner;
return 0;
}


class Dwarf
{
public:
int speed;
int strength;
int number;
};

class Ogres
{
public:
int speed1;
int strength1;
int number1;
};

char fight(void)
{
speed + strength + number = int dwarfpower;
speed1 + strength1 + number1 = int ogrepower;
if(dwarfpower > ogrepower)
winner = "Dwarfs win round" << round;
else
winner = "Ogres win round" << round;
}

bool intro()
{
if(answer = "y")
return true;
else
return false;
return 0;
}

And here's the bugs...
1>------ Build started: Project: Ogres, Configuration: Debug Win32 ------
1>Compiling...
1>ogres.cpp
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(35) : error C2144: syntax error : 'void' should be preceded by ')'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(35) : error C2059: syntax error : ')'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(36) : warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(36) : error C2143: syntax error : missing ';' before ')'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(37) : error C2143: syntax error : missing ';' before '{'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(48) : error C3646: 'cout' : unknown override specifier
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(48) : error C2143: syntax error : missing ';' before '<<'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(70) : error C2601: 'fight' : local function definitions are illegal
1> c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(31): this line contains a '{' which has not yet been matched
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(80) : error C2601: 'intro' : local function definitions are illegal
1> c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(31): this line contains a '{' which has not yet been matched
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(87) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(31)' was matched
1>Build log was saved at "file://c:\Users\Adam\Documents\Visual Studio 2008\Projects\Ogres\Ogres\Debug\BuildLog.htm"
1>Ogres - 9 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

First error:
c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(35) : error C2144: syntax error : 'void' should be preceded by ')'

This means line 35. So, we look in your code at that line, and we find:

if(intro(void))

The problem must something near void, since that's the complaint in the error message. So maybe we meant:

if(intro())

Now you do the same with all the others. The compiler tells you the errors. All you have to do is fix them.


ERROR #1 : answer is set as bool. That's a 0 or 1, true or false. Use a different type of variable to get your y/n response
ERROR #2 : In the for loop for(round = 0; round < 3; round++;) remove the semi-colon after round++
ERROR #3 :
1
2
3
4
5
6
7
8
9
char fight(void)
{
speed + strength + number = int dwarfpower;
speed1 + strength1 + number1 = int ogrepower;
if(dwarfpower > ogrepower)
winner = "Dwarfs win round" << round;
else
winner = "Ogres win round" << round;
}

should be..
1
2
3
4
5
6
7
8
9
char fight(void)
{
int dwarfpower = speed + strength + number;
int ogrepower = speed1 + strength1 + number1;
if(dwarfpower > ogrepower)
winner = "Dwarfs win round" << round; // You have to initialize winner as a string BEFORE you can use it 
else
winner = "Ogres win round" << round; // Same for round as int
}

There's others, but they may become more apparent after these are repaired
closed account (iNU7ko23)
Thanks for your help! I fixed the errors but there's still six more! If anyone else could help me here's the updated version.

#include <iostream>
#include <string>
#include <cstdlib>

using std::cout;
using std::cin;
using namespace::std;

bool intro();

char fight();

int speed = rand();

int strength = rand();

int number = rand();

int speed1 = rand();

int strength1 = rand();

int number1 = rand();

int round = 0;

char answer;

int main()
{
cout << "The Dwarfs and Ogers are about to fight for three rounds!\n";
cout << "Are you ready to fight! y or n";
cin >> answer;
if(intro())
for(round = 0; round < 3; round++;)
{
cout << "Here are the stats...\n";
cout << "DWARFS\n";
cout << "speed = \n" << speed;
cout << "strength = \n" << strength;
cout << "number = \n" << number;
cout << "OGRES\n";
cout << "speed = \n" << speed1;
cout << "strength = \n" << strength1;
cout << "number = \n" << number1;
char fight()
cout << "The winner is " winner;
return 0;
}


class Dwarf
{
public:
int speed;
int strength;
int number;
};

class Ogres
{
public:
int speed1;
int strength1;
int number1;
};

char fight()
{
int dwarfpower = speed + strength + number;
int ogrepower = speed1 + strength1 + number1;
if(dwarfpower > ogrepower)
winner = "Dwarfs win round" << round;
else
winner = "Ogres win round" << round;
}

bool intro()
{
if(answer = "y")
return true;
else
return false;
return 0;
}
closed account (iNU7ko23)
New version with errors...
#include <iostream>
#include <string>
#include <cstdlib>

using std::cout;
using std::cin;
using namespace::std;

bool intro();

char fight();

int speed = rand();

int strength = rand();

int number = rand();

int speed1 = rand();

char winner = " "


int strength1 = rand();

int number1 = rand();

int round = 0;

char answer;

int main()
{
cout << "The Dwarfs and Ogers are about to fight for three rounds!\n";
cout << "Are you ready to fight! y or n";
cin >> answer;
if(intro())
for(round = 0; round < 3; round++)
{
cout << "Here are the stats...\n";
cout << "DWARFS\n";
cout << "speed = \n" << speed;
cout << "strength = \n" << strength;
cout << "number = \n" << number;
cout << "OGRES\n";
cout << "speed = \n" << speed1;
cout << "strength = \n" << strength1;
cout << "number = \n" << number1;
char fight()
cout << "The winner is " winner;
return 0;
}


class Dwarf
{
public:
int speed;
int strength;
int number;
};

class Ogres
{
public:
int speed1;
int strength1;
int number1;
};

char fight()
{
int dwarfpower = speed + strength + number;
int ogrepower = speed1 + strength1 + number1;
if(dwarfpower > ogrepower)
winner = "Dwarfs win round" << round;
else
winner = "Ogres win round" << round;
}

bool intro()
{
if(answer = "y")
return true;
else
return false;
return 0;
}

1>------ Build started: Project: Ogres, Configuration: Debug Win32 ------
1>Compiling...
1>ogres.cpp
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(24) : error C2440: 'initializing' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(24) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(50) : error C3646: 'cout' : unknown override specifier
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(50) : error C2143: syntax error : missing ';' before '<<'
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(72) : error C2601: 'fight' : local function definitions are illegal
1> c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(33): this line contains a '{' which has not yet been matched
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(82) : error C2601: 'intro' : local function definitions are illegal
1> c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(33): this line contains a '{' which has not yet been matched
1>c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(89) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\adam\documents\visual studio 2008\projects\ogres\ogres\ogres.cpp(33)' was matched
1>Build log was saved at "file://c:\Users\Adam\Documents\Visual Studio 2008\Projects\Ogres\Ogres\Debug\BuildLog.htm"
1>Ogres - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
closed account (iNU7ko23)
Any more help?
Double click on the error message; that will most likely lead you to where it is. Then all you have to do is to simply fix what the error message says. These error messages are pretty clear, and you should be able to fix them yourself. By the way, fixing one may lead to another one getting fixed.
closed account (iNU7ko23)
Thanks stupebrett. Yes, I fixed a lot of errors doing this but these are the errors I could not solve.
@adpad309

Here is your program, with three battles. This should get you going in the right direction. Now, you can enhance it with whatever else you had in mind for your program. It does seem like an interesting endeavor.
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
// Ogres Vs Dwarves.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <string>
#include <cstdlib>

using namespace std;

class Dwarves
{
public:
	int speed;
	int strength;
	int number;
} Dwarf[3]; // make 3 sets - 1 for each battle

class Ogre
{
public:
	int speed1;
	int strength1;
	int number1;
} Ogres[3]; // make 3 sets - 1 for each battle

void fight(int);

int round;

char answer ;

int main()
{
	time_t t;

	srand((unsigned) time(&t));
	int a;
	for (a=0;a<3;a++) // loop to give each variable a separate value
	{
		Dwarf[a].speed = 1+rand()%20;  // change these 6 rands() to what you needed
		Dwarf[a].strength = 1+rand()%75;
		Dwarf[a].number = 1+rand()%10;
		Ogres[a].speed1 = 1+rand()%20;
		Ogres[a].strength1 = 1+rand()%75;
		Ogres[a].number1 = 1+rand()%10;
	}
	cout << "The Dwarfs and Ogres are about to fight for three rounds!\n";

	for(round = 0; round < 3; round++)
	{
		answer = 'n';
		while( answer !='Y' && answer !='y')
		{
			cout << "Are you ready to fight! y or n : ";
			cin >> answer;  // must press 'y' to continue
		}
		cout << "Round #" << round+1 << "\n\n"; // Shows stats before the battle
		cout << "Here are the stats...\n";
		cout << "DWARFS :\n";
		cout << "speed = " << Dwarf[round].speed << "\n";
		cout << "strength = " << Dwarf[round].strength << "\n";
		cout << "number of Dwarves = " << Dwarf[round].number << "\n";
		cout << "OGRES : \n";
		cout << "speed = " <<  Ogres[round].speed1 << "\n";
		cout << "strength = " <<  Ogres[round].strength1 << "\n";
		cout << "number of Ogres = " <<  Ogres[round].number1 << "\n\n";
		cout << "The winner of this battle, were ";
		fight(round); // sends round # to function. 
	}
	return 0;
}

void fight(int round)
{
	string winner = "";
	int dwarfpower = Dwarf[round].speed + Dwarf[round].strength + Dwarf[round].number;
	int ogrepower = Ogres[round].speed1 + Ogres[round].strength1 + Ogres[round].number1;
	if(dwarfpower > ogrepower) // Determines Winner
		winner = "the Dwarves.\n\n";
	else
		winner = "the Ogres.\n\n";  
	cout << winner;  // Prints result
}
Last edited on
closed account (iNU7ko23)
@whitenite1
Thanks! This makes much more sense. You're a lifesaver.
Topic archived. No new replies allowed.