Hey everyone=) my name is grux and I've got something of a problem.... First off, let me say that this is NOT for a class, I am simply trying to follow some online tutorials so I can be prepared for college this fall. I'm new to C++ (having only worked with FreeBASIC, LibertyBASIC, and VRML before) and don't understand functions very well. To try and add value to my code (purely a psychological thing for me to understand the point of the code), I act as if I'm programming a Pokemon game.

That being said, I'm getting several error messages when I try to compile this bit of code. What I'm trying to accomplish is to make a function that calculates how much experience your Pokemon gained in the battle it just won, whether it gained a level or not, and if so, is it going to evolve? Anyway, here's the code:

#include <iostream>
#include <cstdlib>

using namespace std;

void battleXpCalc ( int oppLevel, int oppAtk, int oppDef, int oppHp, int myLvl, int myXp, int battleXp, char battlePoke(20), int neededXp, int evoLvl, char evo(3) ); 

int battleXpCalc ( int oppLevel, int oppAtk, int oppDef, int oppHp, int myLvl, int myXp, int battleXp, char battlePoke(20), int neededXp, int evoLvl, char evo(3) ); {
    battleXp = oppLevel + oppAtk + oppDef + oppHp / myLvl;
    myXp = myXp + battleXp;
    cout<< "You just gained "<< battleXp <<" xp! Your "<<battlePoke<<" now";
    cout<< "has "<< myXp <<" !";
    if ( myXp >= neededXp ) {
       myLvl = myLvl + 1;
       cout<< "Congratualtions! Your "<< battlePoke <<" gained a level!";
       neededXp = myXp - battleXp + myLvl;
    }
    if ( evo = "off" ) {
         evoLvl = myLvl + 1;
    }
    if ( myLvl >= evoLvl ) {
       cout<< "What? "<< battlePoke <<" is trying to evolve! He seems determined";
       cout<< "There's no stopping him now!";
    }
    return 0;
}

int main()
{
    int oppLevel, oppAtk, oppDef, oppHp, myLvl, neededXp, evoLvl;
    char battlePoke(20), evo(3);
    oppLevel = 36;
    oppAtk = 78;
    oppDef = 84;
    oppHp = 78;
    myLvl = 35;
    neededXp = 100;
    evoLvl = 36;
    battlePoke = "Wartortle";
    evo = "on";
    battleXpCalc();
    cin.get();
}

my error messages returned are:
6-- expected 'or' before '(' token
6-- ambiguates old declaration `void battleXpCalc(int, int, int, int, int, int, int, char)'
8-- expected 'or' before '(' token
8-- new declaration 'int battleXpCalc(int, int, int, int, int, int, int, char)'
8-- expected unqualified-id before '{' token
8-- expected `,' or `;' before '{' token
~~~~~~~~~~~~~~~~~~~C:\Dev-Cpp\love.cpp In function `int main()':~~~~~~~~~~~~
39-- non-lvalue in assignment
40-- non-lvalue in assignment
8-- too few arguments to function `int battleXpCalc(int, int, int, int, int, int, int, char)'
41-- at this point in file

By the way, I'm using the Bloodshed Dev C++ IDE

Any help would be greatly appreciated=) Thank-you

Recommended Answers

All 7 Replies

>>int battleXpCalc ( int oppLevel, ..., char evo(3) ); {
Undesired semi-colon.

>>char battlePoke(20), int neededXp, int evoLvl, char evo(3)
Not allowed. Default arguments have to be chained.

>>void battleXpCalc
>>int battleXpCalc
Different return type but similar arguments - Not overloaded.

>>battlePoke = "Wartortle";
Can't assign array's like this. Use std::string

>>battleXpCalc();
Call function with arguments.

sorry for the confusion, and thanks for the answer, however I wasn't trying to dimension an array. It said in the tutorial that this is how you determine how many characters are in a string=/

>>sorry for the confusion, and thanks for the answer, however I wasn't trying to dimension an array. It said in the tutorial that this is how you determine how many characters are in a string=/
I think it is arr[20], this I recall resembles SQL. Not sure about this.

Well, thanks for the help:)

I'm still something of a novice programmer, though. If it's not a ton of trouble, would you mind explaining that last bit about calling the function, or point me to something that will help? haha and why do they call them arguments?

>>would you mind explaining that last bit about calling the function
Sure,

int Sum(int a, int b)
{
   return (a+b);
}
int main()
{
  int a;
  a= Sum(2,5);         //Call Sum with parameters 2 & 5
  Sum(2,5);            //Call but doesn't store (useless)
  std::cout<<Sum(2,5); //returned result is taken directly to cout
}

>>why do they call them arguments?
You can call them parameters if you wish.

thanks, friend=) it makes a lot more sense now

Mark this as solved, please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.