My assignment is as follows: Create a higher/lower guessing game using a graphical user interface. allow users to keep guessing until they guess the number. Choose two colors for the game: one should be used to indicate that the value the users guessed is higher than the target; the other is used to indicate the the value the users guesed is lower than the target. With each new guess, change the form color based on whether the guess is higher than the target or lower. Keep a count of the number of guesses it took. when they hit the target display a MessageBox indicating the number of guesses it took. Several approaches can be used to seed the target: one is to generate a random number by the constructing an object of the Randomclass. For example the following stores a random whole number between 0 and 100 in target
Random r = new Random();
int target = r.Next(0,100);
I seem to be having an issue with the "if" statements.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GuessingGame
{
public partial class Form1 : Form
{
//create the form
public Form1()
{
InitializeComponent();
}
//create the button for the random generator
private void btnBegin_Click(object sender, EventArgs e)
{
//initialize the random number generator
Random num = new Random();
//set random number parameters
int range = num.Next(0, 100);
//initialize variables
int guess;
guess = int.Parse(txtBox1.Text);
//parameters to show higher or lower
if (guess > range)
{
Form1.DefaultBackColor(Color.Red);
}
else
if (guess < range)
{
Form.DefaultBackColor(Color.Green);
}
else
{
MessageBox.Show("YOU WIN!");
}
}
private static void DefaultBackColor(Color color)
{
throw new NotImplementedException();
}
}
}
The errors I am receiving are as follows:
Error
1 Non-invocable member 'System.Windows.Forms.Control.DefaultBackColor' cannot be used like a method. C:\Users\Dave Morand\Desktop\Rio Salado\CIS162AD - C# Programming\Lesson 9 Project 2\Guessing Game\Guessing Game\Form1.cs 41 26 Guessing Game
Warning
2 'GuessingGame.Form1.DefaultBackColor(System.Drawing.Color)' hides inherited member 'System.Windows.Forms.Control.DefaultBackColor'. Use the new keyword if hiding was intended. C:\Users\Dave Morand\Desktop\Rio Salado\CIS162AD - C# Programming\Lesson 9 Project 2\Guessing Game\Guessing Game\Form1.cs 49 29 Guessing Game
Error
3 'GuessingGame.Form1' does not contain a definition for 'Form1_Load' and no extension method 'Form1_Load' accepting a first argument of type 'GuessingGame.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\Dave Morand\Desktop\Rio Salado\CIS162AD - C# Programming\Lesson 9 Project 2\Guessing Game\Guessing Game\Form1.Designer.cs 107 55 Guessing Game