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 9165881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:00:52+00:00 2026-06-17T15:00:52+00:00

I am very new to both C# and object-oriented programming. I am trying to

  • 0

I am very new to both C# and object-oriented programming. I am trying to figure out why this program won’t compile. Here is the code snippet that’s giving me trouble:

static void AdvancePreLvlThree() // advances player to next level when level is less than three
{
    if(level == 1)
    {
        xp = (xp - 100); // carries remaining xp over to next level
    }
    else if(level == 2)
    {
        xp = (xp - 150);
    }

    level +=1; // advances
    return Update(); // checks again to see if they can advance further
}

The full program:

///////////////////////////////////////////////////////
//
// A namespace/program for managing experience points 
// and determining if the player can level up.
//
// Written by Jared Beach
// January 19, 2013
//
//////////////////////////////////////////////////////

using System;
namespace LevelSystem
{
    public class LevelSystem 
    {
        public void LevelStorage()
        {
            int level = 1; // stores player level
        }

        public void XPStorage()
        {
            int xp = 0; // stores player xp
        }

        public void XPRequirement() // xp required to advance to the next level
        {
            int maxXP = (8 * level^3);

        static void AdvancePreLvlThree() // advances player to next level when level is less than three
        {
            if(level == 1)
            {
                xp = (xp - 100); // carries remaining xp over to next level
            }
            else if(level == 2)
            {
                xp = (xp - 150);
            }

            level +=1; // advances
            return Update(); // checks again to see if they can advance further
        }

        static void Advance() // advances player to next level
        {
            xp = (level - maxXP); // carries remaining xp over to next level
            level +=1;
            return Update();
        }

        static void Update() // checks to see if player can advance levels
        {
            if(level == 1 && xp > 100) // special case to keep basic progression ratio close to one
            {
                AdvancePreLvlThree();
            }
            else if(level == 3 && xp > 150)
            {
                AdvancePreLvlThree();
            }
            else if(xp >= 3 && xp > maxXP) 
            {
               return Advance();
            }
        }
    }

    public class Program
    {
        static void Main(string[] args)
        {

        }
    }
}

The error I am getting is:

Program.cs(30,8): error CS1525: Unexpected symbol `static'
Program.cs(30,16): error CS1547: Keyword `void' cannot be used in this context
Program.cs(30,38): error CS1525: Unexpected symbol `('
Program.cs(36,16): error CS1519: Unexpected symbol `else' in class, struct, or interface member declaration
Program.cs(36,28): error CS1519: Unexpected symbol `==' in class, struct, or interface member declaration
Program.cs(38,20): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
Program.cs(38,26): error CS1519: Unexpected symbol `-' in class, struct, or interface member declaration
Program.cs(41,12): error CS1525: Unexpected symbol `level'

It’s not in the same class as my Main if that’s relevant.

  • 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-17T15:00:53+00:00Added an answer on June 17, 2026 at 3:00 pm

    As others have stated you need to show all your code in this case because it sounds like something else is missing / wrong in your code and breaking at that point. Here is a working example of what you are trying to do although it doesn’t look like a very good approach having lots of static items and you should really look into Object Oriented Programming!

    namespace ConsoleApplication1
    {
        class Program
        {
            private static int level = 0;
            private static int xp = 0;
    
            static void Main(string[] args)
            {
                AdvancePreLvlThree();
            }
    
            static bool AdvancePreLvlThree() // advances player to next level when level is less than three
            {
                if(level == 1)
                {
                    xp = (xp - 100); // carries remaining xp over to next level
                }
                else if(level == 2)
                {
                    xp = (xp - 150);
                }
    
                level +=1; // advances
                return Update(); // checks again to see if they can advance further
            }
    
            static bool Update()
            {
                // Yes they can...
                return true;
            }
        }
    }
    

    I have made your AdvancePreLvlThree method return a bool as that is what you were trying to do but the method was marked as void? Anyway, hopefully this will get you started?

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

Sidebar

Related Questions

I'm still very new to Object Oriented programming and am having problems with the
I'm completely new to both VB.NET and JSON, and I'm trying to figure out
Very new mobile developer here... I am trying to retrieve a list of tweets
Im very new in C++ I have found this post http://msdn.microsoft.com/en-us/magazine/cc163486.aspx and trying to
This is my first question and I am very new in programming field. I
I'm using MVVM in a WPF app. I'm very new to both. Let me
Very new to python and can't understand why this isn't working. I have a
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Apologies if this doesn't make any sense, I'm very new to Python! From testing
I'm very new to WPF and the EF, and I'm trying to display some

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.