I am trying to create a Number Guessing Game and I'm a little stuck...I have to create a Mystery Number Guessing Game that has two classes, one class being a test class. I have the following so far but its all on one Class(test). I am also having trouble with ending the application after it reaches its 5th attempt. My application needs to include:
1. Two Classes
2. A constructor that creates a random integer between 1-100 stored in an instance variable
3. At least one public Method
4. At least one public property
This is what I have so far.
=====================SEPARATE CLASS=============================
1. Two Classes
2. A constructor that creates a random integer between 1-100 stored in an instance variable
3. At least one public Method
4. At least one public property
This is what I have so far.
C#:
using System;
class MysteryNumber
{
public int RNumber { get; }// auto implemented property
private int random;//instance variable
public MysteryNumber(int myRand)//constructor
{
MyRand = myRand;
}
}
=====================SEPARATE CLASS=============================
C#:
using System;
class MysteryNumberTest
{
static void Main()
{
int myRand;
Random randomNumbers = new Random();
myRand = randomNumbers.Next(1, 100);
int numberOfGuessesLeft = 4;
int numberOfGuessesMade = 1;
while (numberOfGuessesLeft <= 5)
{
Console.Write("Enter A Number Between 1 and 100: ");
int guess = int.Parse(Console.ReadLine());
guess = numberOfGuessesMade;
if (numberOfGuessesMade == myRand)
{
Console.WriteLine($"Good Job! It only took {numberOfGuessesMade}");
}
else if (numberOfGuessesMade != myRand)
{
Console.WriteLine($"Sorry, Try Again. This is guess number {numberOfGuessesMade}, you have {numberOfGuessesLeft} left.");
numberOfGuessesLeft = numberOfGuessesLeft - 1;
numberOfGuessesMade = numberOfGuessesMade + 1;
}
}
Console.ReadLine();
}
}
Last edited by a moderator: