Quick Errors problems?

closed account (iNU7ko23)
Hello
When trying to compile a program I am getting these two errors. Could you please give me a clue what they mean?
Here's the program..

// 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

char winner;

char fight(winner);

int money = 0;

char bet(money);

int round = 0;

char answer;

int main()
{
time_t t;

srand((unsigned) time(&t));
int a;
for (a=0;a < 1000; 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(money = 0; money < 100; 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;
cout << "\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 << "Now place you bets! Can you get to one hundred.\n";
cout << "You have" << money;
cin >> bet;
cout << "You now have" << money;
}
cout << "The winner is... " << fight(winner);
return 0;
}

char fight(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";
return winner;
}

and here's the error report...

1>------ Build started: Project: TEST, Configuration: Debug Win32 ------
1>Compiling...
1>TEST.cpp
1>c:\users\adam\documents\visual studio 2008\projects\test\test\test.cpp(27) : 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\test\test\test.cpp(80) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\users\adam\documents\visual studio 2008\projects\test\test\test.cpp(85) : error C2448: 'fight' : function-style initializer appears to be a function definition
1>Build log was saved at "file://c:\Users\Adam\Documents\Visual Studio 2008\Projects\TEST\TEST\Debug\BuildLog.htm"
1>TEST - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please if you could help me I'd a appreciate it greatly! :)

Don't worry about this...
(If you're reading this whitenite1 check your pm.
You've screwed up the function fight.

What kind of object does it take in? You have to put that in the function definition, like this:

char fight(char winner)

However, if winner is a single char, why are you trying to store more than one char in it?

winner = "the Dwarves.\n\n";
winner is a char, but "the Dwarves.\n\n" is a const char *. How you try to store a const char* in a char? You can't.
Last edited on
closed account (iNU7ko23)
Thanks for your help but I am still really confused. All I intended was for the winner variable to change each time it was called and I don't know why it can't. Also how can it so char winner can store "the Dwarves"
The variable winner can change. You need to pick a sensible type so that the variable winner can hold the data you want it to hold. I suggest a std::string, which you can use if you #include <string> . A std::string will be able to hold lots of letters, wheras a char can hold a single character only.

You also need to declare the function fight properly. I suggest

string fight(string winner);
closed account (iNU7ko23)
// Ogres Vs Dwarves.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <string>
#include <cstdlib>
#include <string>


using namespace::std;
using std::string;


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

string winner;

string fight(string winner);

int money = 0;

char bet(money);

int round = 0;

char answer;

int main()
{
time_t t;

srand((unsigned) time(&t));
int a;
for (a=0;a < 1000; 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(money = 0; money < 100; 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;
cout << "\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 << "Now place you bets! Can you get to one hundred.\n";
cout << "You have" << money;
cin >> bet;
cout << "You now have" << money;
}
cout << "The winner is... " << fight(winner);
return 0;
}

string fight(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";
return winner;
}

thanks alot. I was confused about the char type. BUT there is still 1 error . Here's the code(there's barely any errors...)

// Ogres Vs Dwarves.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <string>
#include <cstdlib>
#include <string>


using namespace::std;
using std::string;


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

string winner;

string fight(string winner);

int money = 0;

char bet(money);

int round = 0;

char answer;

int main()
{
time_t t;

srand((unsigned) time(&t));
int a;
for (a=0;a < 1000; 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(money = 0; money < 100; 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;
cout << "\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 << "Now place you bets! Can you get to one hundred.\n";
cout << "You have" << money;
cin >> bet;
cout << "You now have" << money;
}
cout << "The winner is... " << fight(winner);
return 0;
}

string fight(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";
return winner;
}
and the error is...
1>c:\users\adam\documents\visual studio 2008\projects\test\test\test.cpp(88) : error C2448: 'fight' : function-style initializer appears to be a function definition

string fight(string winner)
Topic archived. No new replies allowed.