Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:32:34+00:00 2026-06-12T06:32:34+00:00

My compiler’s complaining and throwing up an error (see the title) about this code:

  • 0

My compiler’s complaining and throwing up an error (see the title) about this code:

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;
}

The error is on the for(; level < MAX_LEVEL; level++) line, and the full error log looks like (that’s line 50, for reference):

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

Any ideas? I’m assuming I haven’t closed a bracket somewhere, but I just can’t find it.
As I suspect this may be the case, here’s the full code for that file:

#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;
}

and the main.h it references:

#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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:32:35+00:00Added an answer on June 12, 2026 at 6:32 am

    Remove the the trailing semi-colon from the MAX_LEVEL macro:

    #define MAX_LEVEL 99;
    

    as when the macro is replaced in the for loop it becomes:

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

    which is illegal syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The compiler complains about this code: HashMap<String,int> userName2ind = new HashMap<String,int>(); for (int i=0;
The compiler complains about this: int randomSort(id obj1, id obj2, void *context) { //
my compiler throws error: expected ';' before '<' token on this line of code:
Compiler Error Keyword 'this' is not available in the current context delegate void CallBack(int
The compiler complains about this, after I activated all kind of warnings: For MyApp_Prefix.pch
g++ compiler gives this error: expected `;' before 'it' template <typename T> class myList
The compiler is always complaining about: Object reference not set to an instance of
For compiler-specific code, it's common to see cpp directives such as: #if defined (__GNUC__)
Does compiler optimization cause a problem with code like this? Specifically, can the auto-increments
My compiler, MPLAB C30 (GCC v3.23) is not compiling this code: if(font_info.flags & FONT_LOWERCASE_ONLY)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.