this is my code for my class but i can't get it to work when i use Y or N for true and false with the boolean, how do i get it to work?
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Lab6 { class Program { static void Main(string[] args) { System.Random RandNum = new System.Random();
bool prompt; int min, max;
min = 1; max = 6;
bool yes = true;
bool no = false;
do { Console.WriteLine("Do you want to roll the dice? (Y or N)");
prompt = bool.Parse(Console.ReadLine());
if (prompt == yes) { int dice1 = RandNum.Next(min, max); int dice2 = RandNum.Next(min, max);
if (dice1 == 6 & dice2 == 6) { Console.WriteLine("You rolled a boxcar"); } if (dice1 == 1 & dice2 == 1) { Console.WriteLine("You rolled snake eyes"); } else { Console.WriteLine("You rolled a {0} and a {0}", dice1, dice2); } }
else { Console.WriteLine("Thank you, come again"); Console.WriteLine("Good Bye :)"); } } while (prompt == yes); Console.ReadLine(); } } }
|
| Author: Anuraj 22 Oct 2009 | Member Level: Diamond | Rating:    Points: 6 |
Try this
prompt = Console.ReadLine(); ...
if (prompt == "y" || prompt == "Y") { //Do something }
Thanks Anuraj THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS. BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT. dotnetthoghts
|
| Author: Sean 22 Oct 2009 | Member Level: Bronze | Rating:  Points: 2 |
Thanks that helped a lot, it works now.
|