Click here to Skip to main content
14,486,801 members
Rate this:
Please Sign up or sign in to vote.
See more:
#include <iostream>
#include <string>
using namespace std;
struct Player {

	char name [50];
	char player_class [50];
	unsigned short int level;
	float exp;
	bool competitive;
};
struct Battle {

	char battle_name[50];
	char battle_favour_class[50];
	int min_level;
	int xp;
};
void show_player (const Player & player)
{

if (player.competitive )
	cout<<player.name<<" is a competitive level "<<player.level <<player.player_class<<"\n";
else
	cout<<player.name<<" is an amateur level "<<player.level <<player.player_class<<"\n";

}
void encounter(Player,Battle)
{

if (Player1.level && Player2.level <Battle.min_level)
	cout<<"Not Valid Encounter\n";
else if (Player1.level>Battle.min_level && Player2.level<Battle.min_level)
	cout<<"The winner is "<<Player1;
else if (Player1.level<Battle.min_level && Player2.level>Battle.min_level)
	cout<<"The winner is "<<Player2;
else if (Player1.level &&Player2.level >=Battle.min_level)
	cout<<"Valid Encounter";
	if(Player1.player_class>Battle.battle_favour_class && Player2.player_class<Battle.battle_favour_class)
		cout<<"The winner is"<<Player1;
	else if (Player1.player_class<Battle.battle_favour_class && Player2.player_class>Battle.battle_favour_class)
		cout<<"The winner is"<<Player2;
	else if (Player1.player_class>Battle.battle_favour_class && Player2.player_class>Battle.battle_favour_class)
		if(Player1.exp>Player2.exp)
			cout<<"The winner is "<<Player1;
		else if(Player1.exp<Player2.xp)
			cout<<"The winner is "<<Player2;
	else if (Player1.player_class<Battle.battle_favour_class && Player2.player_class<Battle.battle_favour_class)
		if(Player1.exp>Player2.exp)
			cout<<"The winner is "<<Player1;
		else if(Player1.exp<Player2.exp)
			cout<<"The winner is "<<Player2;
	else if (Player1.exp=Player2.exp)
		cout<<"Tie";
}
int exp_winner(Player,Battle);
{

 if(Player1.level>Battle.min_level || Player1.player_class>Battle.battle_favour_class || Player1.exp>Player2.exp)
	Player1.exp=Player1.exp + Battle.xp
else if(Player2.level>Battle.min_level || Player2.player_class>Battle.battle_favour_class || Player2.exp>Player1.exp)
	Player2.exp=Player2.exp + Battle.xp
}
int main(){
}


What I have tried:

#include <iostream>
#include <string>
using namespace std;
struct Player {

	char name [50];
	char player_class [50];
	unsigned short int level;
	float exp;
	bool competitive;
};
struct Battle {

	char battle_name[50];
	char battle_favour_class[50];
	int min_level;
	int xp;
};
void show_player (const Player & player)
{

if (player.competitive )
	cout<<player.name<<" is a competitive level "<<player.level <<player.player_class<<"\n";
else
	cout<<player.name<<" is an amateur level "<<player.level <<player.player_class<<"\n";

}
void encounter(Player,Battle)
{

if (Player1.level && Player2.level <Battle.min_level)
	cout<<"Not Valid Encounter\n";
else if (Player1.level>Battle.min_level && Player2.level<Battle.min_level)
	cout<<"The winner is "<<Player1;
else if (Player1.level<Battle.min_level && Player2.level>Battle.min_level)
	cout<<"The winner is "<<Player2;
else if (Player1.level &&Player2.level >=Battle.min_level)
	cout<<"Valid Encounter";
	if(Player1.player_class>Battle.battle_favour_class && Player2.player_class<Battle.battle_favour_class)
		cout<<"The winner is"<<Player1;
	else if (Player1.player_class<Battle.battle_favour_class && Player2.player_class>Battle.battle_favour_class)
		cout<<"The winner is"<<Player2;
	else if (Player1.player_class>Battle.battle_favour_class && Player2.player_class>Battle.battle_favour_class)
		if(Player1.exp>Player2.exp)
			cout<<"The winner is "<<Player1;
		else if(Player1.exp<Player2.xp)
			cout<<"The winner is "<<Player2;
	else if (Player1.player_class<Battle.battle_favour_class && Player2.player_class<Battle.battle_favour_class)
		if(Player1.exp>Player2.exp)
			cout<<"The winner is "<<Player1;
		else if(Player1.exp<Player2.exp)
			cout<<"The winner is "<<Player2;
	else if (Player1.exp=Player2.exp)
		cout<<"Tie";
}
int exp_winner(Player,Battle);
{

 if(Player1.level>Battle.min_level || Player1.player_class>Battle.battle_favour_class || Player1.exp>Player2.exp)
	Player1.exp=Player1.exp + Battle.xp
else if(Player2.level>Battle.min_level || Player2.player_class>Battle.battle_favour_class || Player2.exp>Player1.exp)
	Player2.exp=Player2.exp + Battle.xp
}
int main(){
}
Posted
Updated 27-Feb-20 2:21am
Comments
k5054 26-Feb-20 14:44pm
   
We're not going to compile your code and fix your errors for you. You should tell us what "mistakes" you have, and where they are in the code. Perhaps then someone will point you towards a solution.

That being said, there's no body to your main(), so at best the program just exits, assuming it compiles cleanly.
Rate this:
Please Sign up or sign in to vote.

Solution 1

For starters, this
if (Player1.level && Player2.level <Battle.min_level)
is simply incorrect and must be written as
if((Player1.level < Battle.min_level) && (Player2.level < Battle.min_level))
Adding parentheses around expressions is a good idea unless you're certain of operator precedence. As written, it won't even compile.
void Encounter(Player, Battle)
should be something like
void Encounter(Player& player1, Player& player2, Battle& battle)
with the lowercase names used inside the function. You probably also want the function to return something that indicates who won. Finally, nothing will happen unless main() does something or calls a function. You should also format your code and add some comments so that it's easier for others to tell what you're trying to do.
   
v4
Comments
Stefan_Lang 27-Feb-20 8:09am
   
Actually the compiler will accept that if statement and produce a completely useless result at runtime.
Rate this:
Please Sign up or sign in to vote.

Solution 3

When you get compiler errors, just start with the first one. Depending on the severity and type of the error, the compiler may have trouble interpreting the follow up code correctly and produce more error messages than there really are.

In your case, the first error points at the first line in function encounter():
void encounter(Player,Battle)
{
    if (Player1.level && Player2.level <Battle.min_level)

The error message states that
Quote:
'Player1' was not declared in this scope

or something along these lines, dependent on your compiler. What this means is that the compiler tried to find out what the symbol 'Player1' is, and didn't find a definition for it! If you look at the following compiler errors, you'll spot the same message regarding 'Player2'.

The mistake you made is that you intended to pass the players to the function as arguments, but forgot to write out the full argument definition. You should therefore change the function definition to
void encounter(const Player& Player1, const Player& Player2, Battle& Battle1)

Note that you hadn't specified a argument name for your Battle instance either!

With these changes, a lot of the errors vanish. But new ones pop up, referring to later parts of the code.

Continue like that, each time dealing with only the very first error message, and you should be able to compile your code.

If you're stuck in that process at any point, you can come back and ask about the specific error you don't know how to fix.
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
C++ need help lot of mistakes

You forgot to tell what are your expectations for this code and what errors you get.

int main(){
}

This code does nothing, and it is normal, but is it what you want ?

ou need to practice C++ syntax:
 if(Player1.level>Battle.min_level || Player1.player_class>Battle.battle_favour_class || Player1.exp>Player2.exp)
	Player1.exp=Player1.exp + Battle.xp  // semicolumn missing at the end of this line
else if(Player2.level>Battle.min_level || Player2.player_class>Battle.battle_favour_class || Player2.exp>Player1.exp)
	Player2.exp=Player2.exp + Battle.xp  // semicolumn missing at the end of this line
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100