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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:30:58+00:00 2026-06-13T08:30:58+00:00

Perhaps this could be more clear. The method is returning values…but after the value

  • 0

Perhaps this could be more clear. The method is returning values…but after the value is returned I have no access to it in the rest of the program. I put a comment on the difficult part.

class CharacterStats
{
    public int CharacterHitPoints()
    {
        int Health = 0;            
        Random rnd = new Random();
        Health = rnd.Next(30,70);
        return (Health);
    }

    public int CharacterStrength()
    {
        int Strength = 0;
        Random rnd = new Random();
        Strength = rnd.Next(1,20);
        return (Strength);
    }
}

class ApplicationObject
{
    static void Main()
    {
      string CharName;
      string KeepStats;

      MonsterAttackRolls GoblinAttack = new MonsterAttackRolls();
      MonsterAttackRolls OrcAttack = new MonsterAttackRolls();
      MonsterAttackRolls OgreAttack = new MonsterAttackRolls();
      MonsterAttackRolls DragonAttack = new MonsterAttackRolls();

      MonsterHitPoints GoblinHealth = new MonsterHitPoints();
      MonsterHitPoints OrcHealth = new MonsterHitPoints();
      MonsterHitPoints OgreHealth = new MonsterHitPoints();
      MonsterHitPoints DragonHealth = new MonsterHitPoints();

      CharacterStats PlayerHealth = new CharacterStats();
      CharacterStats PlayerStrength = new CharacterStats();

      Console.WriteLine("Welcome to Realm, the top adventure game in the world!  Please enter the name of your character if you wish to continue:");
      CharName = Console.ReadLine();

      Console.WriteLine("Welcome {0} to Realm!  You will be given stats.  They may be good or they may be bad.\nYou only get 2 rolls for your stats though, so pick wisely!  From there you must fight 4 fearsome beasts.\n  If you survive, you will win the game.  If you die, well, you die.  Press any key to continue.", CharName);
      Console.ReadLine();

      Console.WriteLine("You will be given a strength number which augments your damage. Your strength can range from 1 - 20.\n A strength of 15 or over gives you a bonus to damage.  A strength of 5 or less gives you a penalty.   You will be start with a hit point number between 30-70.  Good luck!");
      Console.ReadLine();

      Console.WriteLine("Your first set of stats is:\n Health = {0}.\nYour strength is {1}.\nIf you would like to roll again press 1.  If you want to keep your stats press any other key.", PlayerHealth.CharacterHitPoints(), PlayerStrength.CharacterStrength());
      KeepStats =  Console.ReadLine();

      if (KeepStats == "1")
      {
          Console.WriteLine("So you want a second set of stats.  Okay.\n Your health is now: {0}.\n Your strength is now: {1}.", PlayerHealth.CharacterHitPoints(), PlayerStrength.CharacterStrength());
          Console.ReadLine();
      }



        Console.WriteLine("Okay {0} you are ready to go.  Good luck!\n.  Once again, your stats are:  Health: {1}\n Strength: {2}", CharName, //How do I access the return value? x 2?;
        Console.ReadLine();
    }







    }
}

Where the comments are in the line just above this is where I want to put the returned values and have access for them the rest of the program.

  • 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-13T08:30:59+00:00Added an answer on June 13, 2026 at 8:30 am
    CharacterStats charObj = new CharacterStats();
    int CharacterStrengthInt = charObj.CharacterStrength();
    int CharacterHitPointsInt = charObj.CharacterHitPoints();
    

    EDIT:, since your edited question makes it more clear. I believe you are looking for following.

    You need to assign the return values to some variable in your code and then display the values of those variables in Console.WriteLine. Otherwise they will be lost.

    Something like following.

    int CharacterStrengthInt = PlayerStrength.CharacterStrength();
    int CharacterHitPointsInt = PlayerHealth.CharacterHitPoints();
     if (KeepStats == "1")
          {
            Console.WriteLine("So you want a second set of stats.  Okay.\n Your health is now: {0}.\n Your strength is now: {1}."
           , CharacterHitPointsInt, CharacterStrengthInt);
              Console.ReadLine();
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is perhaps more of a discussion question, but I thought stackoverflow could be
I have an ObjectDataSource (but perhaps this question is the same for all kinds
UPDATE: Perhaps this wasn't clear from my original post, but I'm mainly interested in
Perhaps a fresh set of eyes could help me with this. I thought this
This question is just out of interest, and perhaps could be useful for my
this newbie here is smacking his head with webservices over Rails. Perhaps someone could
Perhaps this is an effect of installing the new 4.5 beta, but my simulator
Perhaps this question has been asked elsewhere, but I'm unable to find it. With
Perhaps this has something to do with it being the mainForm, but I'll ask
I'm new to visual studio, so perhaps this is something easy... but I've had

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.