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!
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 :
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
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 ==========
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.
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.
// Ogres Vs Dwarves.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <string>
#include <cstdlib>
usingnamespace 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
}