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

  • Home
  • SEARCH
  • 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 6016681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:01:04+00:00 2026-05-23T03:01:04+00:00

I have been programming for about 3 years now and feel confident in my

  • 0

I have been programming for about 3 years now and feel confident in my skills. But recently I began working alongside embedded systems and working on other peoples code and have begun to question how good my code is.

I see all these complex answers on SO and think I would have done that with a vector and if statements and wonder if I am any more than a beginner as I was self taught and don’t really know my level.

So I was wondering if more experienced programmers could show me ho to do things better.

This is code I wrote to for an rpg game to pick a target to attack. using it as an example could you show me better/more advanced/professional ways of doing it.

int FindTarget(Player &player);
{
    int aimPoint[5] = 0;

    for(int i  = 0; i <= 5; i++)
    {
        if(player.team[i].exist == true)
        {
            // set random starting point between 1 - 3 
            aimPoint[i] = random /3;

            // add a point if you hve an elemental advantage minus if not
            if(player.team[i].type == weak)
            {
                aimPoint += 1;
            }
            else if(player.team[i].type == strong)
            {
                aimPoint -= 1;
            }

                //add for front row minus for back
            if(i == 1 || i== 3)
            {
                aimPoint += 1;
            }
            else
            {
                aimPoint -= 1;
            }
        }
    }

    return 0;
}

EDIT: If you don’t have the time or effort to show me examples I would appreciate a good book that a beginner/intermediate could understand.

  • 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-05-23T03:01:05+00:00Added an answer on May 23, 2026 at 3:01 am

    ahem since nobody mentioned it, let me point this one out:

    int FindTarget(Player &player);
    {
       int aimPoint[5] = 0;
    
       ...
       return 0
    }
    

    to roughly

    void FindTarget(const Player &player)
    {
        std::vector<int> aimPoint(5, 0);
        ...
    }
    

    Also, since there is no knowing what the code should do (and how ‘aimPoint’ is related to teams; guessing doesn’t help because none of it is used, aimPoint is discarded?), I don’t have anything else than fixing the obvious breakage that was above

    —- Edit from a comment

    The handling of random seems misguided. Someone suggested that you might have meant random %3 + 1;

    I noted that too but decided there is nothing to base the assumption on. Perhaps random is already an int in the range [3, 12).

    Also, random % 3 won’t yield a uniform distribution, so you’d need to do something else

    For many applications, rand() will perform admirably when used correctly, but with the current sad state of affairs, rand() is very rarely used correctly.

    The problem is that of distribution

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

Sidebar

Related Questions

Beginner in python, but been programming for about 5 years now. I suspect I
I've been programming C, mainly in an embedded environment, for years now and have
I have been programming in Perl, off and on, for years now, although only
I have been programming 10 years, mostly in vba and vb.net but I know
I have been programming in C for a couple of years in Linux. Now
I have been doing Windows programming in .Net since last two years. Now I
I have been programming in Python for a few years now and have always
Although I have been programming for about 11 years(mostly VB6, last 6 months C#),
I've been programming in PHP for years now, but I've never learned how to
I have been programming in C++ on and off for about 5 years, why

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.