I just started learning C# and I'm trying to make a little month guesser for my class, where you input the birth month and then it guesses the month you were born. At first I used an array for the months but then changed it to a list. I've ended up with it saying, "the name months cannot be found in the current context" and I'm not sure how to fix it although I bet it's a simple fix. Here is the code:
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
Console.WriteLine("Welcome to the month guessing game!");
Console.WriteLine("I will try to guess your birth month and age!");
Console.WriteLine("Alright, so first of all are you born in 2008 or 2007?");
bool year;
string answer = Console.ReadLine();
if (answer == "2007") {
year = true;
var months = new List<string>{ "September", "October", "November", "December"};
}
else {
year = false;
var months = new List<string>{ "Janurary", "February", "March", "April", "May", "June", "July", "August"};
}
if (year == true) {
bool i = true;
while (i == true) {
var random = new Random();
int index = random.Next(months.Count);
Console.WriteLine("I guess...");
Console.WriteLine(months[index]);
Console.WriteLine("Was this correct?");
Console.WriteLine("Type yes or no?");
string ans2 = Console.ReadLine();
if (ans2 == "yes" || ans2 == "Yes") {
i = false;
Console.WriteLine("Im a genius!");
}
}
}
if (year == false) {
bool i = true;
while (i == true) {
Random rnd = new Random();
int index2 = rnd.Next(months.Length);
Console.WriteLine("I guess...");
Console.WriteLine(months[index2]);
Console.WriteLine("Was this correct?");
Console.WriteLine("Type yes or no?");
string ans2 = Console.ReadLine();
if (ans2 == "yes" || ans2 == "Yes") {
i = false;
Console.WriteLine("Im a genius!");
}
}
}
}
}
I hope someone can help and thank you for reading.