Jump to content
  • Advertisement
Sign in to follow this  
jakpandora

more problems with code(still need help!)

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, I tried to add the two other weapons to my game, but I got similar errors agin.
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

//Declare global variables
int health = 100;  //Player health
int enemyh = 100;  //Enemy health
int weapon;  //Current weapon
int ch1 = 1; //weapon choice 1
int ch2 = 2; //weapon choice 2
int ch3 = 3; //weapon choice 3
int heal;  //heal the character
int choice; //turn choice
int att = 1; //Player attacks
int hel = 2; //heal

 void battle() {               
  cout<<"It is your turn. what do you do?(1 to attack and 2 to heal)"<< endl;
  cin>> choice;
  if (choice == att) {
  cout<<"You have attacked him!"<< endl;
  enemyh = enemyh - 10;
  cout<<"He now has "<< enemyh<<" health left"<< endl;
  }
  if (choice == hel) {
  cout<<"You have healed your-self!"<< endl;
  health = health + 20;
  cout<<"You now have "<< health<<" health left"<< endl;
  }
}

 void ebattle() {   
  cout<<"It is his turn to attack! he has struck you with his mighty weapon!"<< endl;
  health = health - 12;
cout<<"you now have only "<< health<< " health left!"<<endl;
  }

  void battle2() {
  cout<<"It is your turn. what do you do?(1 to attack and 2 to heal)"<< endl;
  cin>> choice;
  if (choice == att) {
  cout<<"You have attacked him!"<< endl;
  enemyh = enemyh - 12;
  cout<<"He now has "<< enemyh<<" health left"<< endl;
  }
  if (choice == hel) {
  cout<<"You have healed your-self!"<< endl;
  health = health + 15;
  cout<<"You now have "<< health<<" health left"<< endl;
  }

  void battle3() {  //LINE 56
  cout<<"It is your turn. what do you do?(1 to attack and 2 to heal)"<< endl;
  cin>> choice;
  if (choice == att) {
  cout<<"You have attacked him!"<< endl;
  enemyh = enemyh - 8;
  cout<<"He now has "<< enemyh<<" health left"<< endl;
  }
  if (choice == hel) {
  cout<<"You have healed your-self!"<< endl;
  health = health + 30;
  cout<<"You now have "<< health<<" health left"<< endl;
  }

  void ebattle2() {  //LINE 70
  cout<<"It is his turn to attack! he has struck you with his mighty weapon!"<< endl;
  health = health - 10;
cout<<"you now have only "<< health<< " health left!"<<endl;
 }

 void ebattle3() {
 cout<<"It is his turn to attack! he has struck you with his mighty weapon!"<< endl;
  health = health - 12;
cout<<"you now have only "<< health<< " health left!"<<endl;
}

int main(int argc, char *argv[])
{
  cout<<"Armor core arenas"<< endl;
  cout<< endl;
  cout<<"Welcome to armor core arenas! The game where you fight against your"<< endl;
  cout<<"opponent in an arena with a weapon of your choice."<< endl;
  cout<<endl;
  cout<< endl;
  cout<< endl;
  cout<<"Please choose your weapon"<< endl;
  cout<<"1.  axe"<< endl;
  cout<<"2.  sword"<< endl;
  cout<<"3.  staff(magic)"<< endl;
  cin>> weapon;
  if (weapon == ch1) {
  cout<<"You have chosen the axe. The battle will now comence!"<< endl;}
  cout<<"your opponet will be the crusher. he is a large opponet who also weilds an axe"<< endl;
  cout<< endl;

 while(health>0){
  battle();
  ebattle();}

  if (weapon == ch2) {
  cout<<"You have chosen the sword. a mighty weapon that can quickly slice through opponets. The battle will now commence!"<< endl;
  cout<<"Your opponet will be the hunter. A swift enemy who uses his bow and arrow to a great advantage"<< endl;
  cout<< endl;

while(health>0){
  battle2();
  ebattle2();}  //LINE 112

  if (choice == ch3) {
  cout<<"You have chosen the magic staff. a mystical item that has extrodinary powers. The battle will now commence!"<< endl;
  cout<<"Your opponet is the wizard ar naria. a powerful wizard with unknown powers."<< endl;
  cout<< endl;
  
 while(health>0){
  battle3();
  ebattle3();}  //LINE 120
 
  return 0;
} 


I get the following errors: implicit declaration of function 'int ebattle2(...)' implicit declaration of function 'int battle3(...)' parse error before { (line 56) parse error before { (line 70) parse error at end of input (last line) so, whats wrong? you know, I think I would be better at this stuff if I actually understood what the errors meant. I know some, but very little. is there an easier way to understand this stuff? [Edited by - jakpandora on August 17, 2004 8:27:30 AM]

Share this post


Link to post
Share on other sites
Advertisement
u are missing some brackets..

When you create a function ALWAYS create both brackets before proceding.

At the end of ur if statement in both battle2 and battle3 you are missing brackets.... Like I said before get a C++ book it will help you lots.

Share this post


Link to post
Share on other sites
Quote:
Original post by jakpandora
implicit declaration of function 'int ebattle2(...)'
implicit declaration of function 'int battle3(...)'

Implicit declaration of a function, means that you're calling a function that you haven't declared. In the first case, you don't have an ebattle2 function, but you do have a battle2 function. May I suggest putting a little more thought into function (and variable) names?
EDIT: Ok, you do have an ebattle2 function.. Didn't see it, but that just illustrates my point about the function names... So the problem is the same as in the second case.
In the second case, it's because of the parse error. It's hard to see because of the lack of indentation, but it seems that you've forgotten the closing '}' for battle2().
Quote:
parse error before { (line 56)
parse error before { (line 70)
parse error at end of input (last line)

The two first ones seem to be because you haven't ended your functions with '}'
Fixing those should fix the last one too.

Share this post


Link to post
Share on other sites
I compiled your code and it seems that you have local declaration functions ,try fix that .
You can get the significance of errors by looking for them in
msdn

Share this post


Link to post
Share on other sites
actually, I do have a c++ book, its just *really* bad. I cant afford to get a mew one at the moment, but when I do, im leanring everything all over again. thanks.

Share this post


Link to post
Share on other sites
I am still having problems. I fixed the code, and now I have one eror:

parse error at end of input

it is on the last line, the one with the closing curly brace. any help

Share this post


Link to post
Share on other sites
jakpandora,

May I suggest you use Thinking in C++? It's a free book, which you can either work through online, or offline (scroll down the page a little for a download site).

I don't know what book you're reading, but your code is very, very messy (I don't mean that to offend - we all have to start somewhere).

What the others have said about indentation and naming conventions, will certainly help you a lot. Even if you don't know what an error means, it's much easier to track it down if your code is readable. Don't be afraid to use white-space in order to make things easier to read. In fact, I'd strongly advise that you do make use of white-space.

Here's an example from your code:


void battle() {
cout<<"It is your turn. what do you do?(1 to attack and 2 to heal)"<< endl;
cin>> choice;
if (choice == att) {
cout<<"You have attacked him!"<< endl;
enemyh = enemyh - 10;
cout<<"He now has "<< enemyh<<" health left"<< endl;
}
if (choice == hel) {
cout<<"You have healed your-self!"<< endl;
health = health + 20;
cout<<"You now have "<< health<<" health left"<< endl;
}
}



This would be much easier to read, and hence maintain, if you used some indentation:


void battle()
{
cout << "It is your turn. what do you do?(1 to attack and 2 to heal)" << endl;
cin >> choice;

if (choice == att)
{
cout << "You have attacked him!" << endl;
enemyh = enemyh - 10;
cout << "He now has " << enemyh << " health left" << endl;
}
if (choice == hel)
{
cout << "You have healed your-self!" << endl;
health = health + 20;
cout << "You now have " << health << " health left" << endl;
}
}



You only need to press the TAB key once, in order to get a nice indent. Some people prefer using spaces, but that's personal preference. I like using TAB, being as you only need to press it once, and not three or four times for the same effect. Also, note the extra spacing I've added, between statements such as cin >> choice;. Again, it makes things much easier to read.

Strongly consider looking at Thinking in C++. Bad habits are harder to "unlearn", if there is such a word, than they are to prevent in the first place.

-hellz

Share this post


Link to post
Share on other sites
I am using dev c++ 4. anybody know why this has happened? I have seen it before, and it usually goes away when I fix my code. oh, and ill check out that book. hopefully it will help.

Share this post


Link to post
Share on other sites
"parse error at end of input" is probably because of unbalanced {}..
You seem to have lots of them. Like this:
  if (weapon == ch2) {
cout<<"You have chosen the sword. a mighty weapon that can quickly slice through opponets. The battle will now commence!"<< endl;
cout<<"Your opponet will be the hunter. A swift enemy who uses his bow and arrow to a great advantage"<< endl;
cout<< endl;

As been said before indentate your code better! It will help you find these errors faster.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!