C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Visual Studio »

How do i make this work?


Posted Date: 22 Oct 2009      Posted By: Sean      Member Level: Bronze     Points: 1   Responses: 2



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();
}
}
}





Responses

Author: Anuraj    22 Oct 2009Member Level: DiamondRating: 4 out of 54 out of 54 out of 54 out of 5     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 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

Thanks that helped a lot, it works now.


Post Reply
You must Sign In to post a response.
Next : Crystal reports issues
Previous : Is it possible to generate report from two different tables
Return to Discussion Forum
Post New Message
Category: Visual Studio

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use