2012-10-03 4 views
2

제 컴파일러의 불평이 코드에 대한 오류 (제목 참조) 던지고 :(C++) 오류 : ';'앞에 예상 기본 표현식이 있습니다. 토큰

int toLevel(int xp) 
{ 
    int points = 0; 
    int level = 1; 
    for(; level < MAX_LEVEL; level++) 
    { 
     points += floor(level + 300*pow(2, level/7.)); 
     if(xp < points) 
     { 
      break; 
     } 
    } 
    return level; 
} 

오류가 for(; level < MAX_LEVEL; level++) 라인에 있고 (즉, 라인 (50)의 참조)처럼 전체 오류 로그가 보인다 :

In function 'int toLevel(int)': 
50 error: expected primary-expression before ';' token 
50 error: expected ')' before ';' token 
50 error: expected ';' before ')' token 
48 warning: unused variable 'points' 
59 error: expected '}' at end of input 
59 warning: no return statement in function returning non-void 
=== Build finished: 4 errors, 2 warnings === 

아이디어가 있으십니까? 나는 어딘가에 브래킷을 닫지 않았다고 가정하지만, 나는 그것을 찾을 수 없다. 나는이 사건 될 수있다 생각으로 , 여기에 파일의 전체 코드입니다 :

#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <vector> 
#include <math.h> 

using namespace std; 

#define MAX_LEVEL 99; 

#include "main.h" 

int main() 
{ 
    Player player; 
    loadSkills(player); 
    if(!loadGame(player)) 
    { 
     cout << "It looks like its your first time playing." << endl; 
     cout << "What's your name?: "; 
     cin >> player.name; 
    } 
    cout << "Hello " << player.name << ", you're level " << toLevel(player.xp) << endl; 
    //TODO 
    return 0; 
} 

//Returns true if loaded, false otherwise 
bool loadGame(Player player) 
{ 
    //TODO 
    return false; 
} 

void loadSkills(Player player) 
{ 
    vector<Skill> skills; 
    skills.push_back((Skill){"Melee"}); 
    skills.push_back((Skill){"Woodcutting"}); 
    skills.push_back((Skill){"Firemaking"}); 
    skills.push_back((Skill){"Fishing"}); 
    skills.push_back((Skill){"Cooking"}); 
    player.skills = skills; 
} 

int toLevel(int xp) 
{ 
    int points = 0; 
    int level = 1; 
    for(; level < MAX_LEVEL; level++) 
    { 
     points += floor(level + 300*pow(2, level/7.)); 
     if(xp < points) 
     { 
      break; 
     } 
    } 
    return level; 
} 

은과 main.h 그것은 참조 :

#ifndef MAIN_H_INCLUDED 
#define MAIN_H_INCLUDED 

vector<string> &split(const string &s, char delim, vector<string> &elems) { 
    stringstream ss(s); 
    string item; 
    while(getline(ss, item, delim)) { 
     elems.push_back(item); 
    } 
    return elems; 
} 

//Ease of use method 
vector<string> split(const string &s, char delim) { 
    vector<string> elems; 
    return split(s, delim, elems); 
} 

struct Skill 
{ 
    string name; //The name of the skill 
}; 

struct Player 
{ 
    int health;    //The player's current health 
    int xp;     //The player's xp 
    int maxhealth;   //The player's max health 
    vector<Skill> skills; //The skills available to the player 
    string name;   //The player's name 
}; 

class InteractOption 
{ 
    public: 
    void doAction();//What should happen 
    bool succeeded; //If true, they get the xp for it. 
    int xp;   //Amount of xp gained for doing 
    Skill skill; //Skill to gain xp in 
    string name; //"Chop"/"Attack"/etc 
}; 

class WorldObject 
{ 
    public: 
    InteractOption interactOption; //The option for interacting with the object. 
            //Can be null (i.e. can't interact) 
    string name;     //"Tree"/"Goblin"/etc 
}; 

bool loadGame(Player); 
void loadSkills(Player); 
int toLevel(int); 

#endif // MAIN_H_INCLUDED 

답변

7

MAX_LEVEL에서 후행 세미콜론을 제거 매크로 매크로는 for 루프로 교체 될 때

#define MAX_LEVEL 99; 

그것대로 :

for(; level < 99;; level++) 

이는 잘못된 구문입니다.

+0

물론! 글쎄, 나는 바보 같아. –

+0

고마워, 고마워! :디 –

관련 문제