# dice guessing game

Page 1 of 1

## 1 Replies - 3409 Views - Last Post: 29 September 2008 - 10:33 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=65479&amp;s=2ad8f9dff68ccc991a6fe840a97e7acd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 red_4900

• Code T(h)inkers

Reputation: 21
• Posts: 1,120
• Joined: 22-February 08

# dice guessing game

Posted 29 September 2008 - 09:16 AM

Just translating the dice guessing game from C++ to C#. I think I got the logic correct there.

```using System;
namespace randDice
{
class randDice
{
static void Main(string[] args)
{
int diceNmbr, guess, cont;
string input, guessStr;
Random dice = new Random();
Console.WriteLine("Welcome to the guee the dice number game.");
Console.WriteLine("Guess between number 1 to 6.");
do
{
diceNmbr = (int)(dice.NextDouble() * 6) + 1;
Console.WriteLine("Dice number : {0}",diceNmbr);
do
{
guess = Int32.Parse(input);
if ((guess < 1) || (guess > 6))
Console.WriteLine("Choose between the number 1 to 6 only.");
}while((guess>=1)||guess<=6);

if (guess > diceNmbr)
Console.WriteLine("Too big. Try again.");
else if (guess < diceNmbr)
Console.WriteLine("Too small. Try again.");
else
Console.WriteLine("Great guess!!");

Console.WriteLine("Do you wish to continue? Press 1 to continue or 0 to quit.");
cont = Int32.Parse(guessStr);
}while(cont==1);
}
}
}
```

I get it right till the checking part (line 17-23). My problem is after that. No matter what the condition is, the program will not tell whether the guessed number is too big or too small or whether is it correct. Can someone tell me what went wrong?

Any help is greatly appreciated.

edit : never mind. I already figured out what went wrong. the 2nd do-while should be while((guess < 1)||guess > 6), not while((guess>=1)||guess<=6). Sorry for bothering you guys.

This post has been edited by red_4900: 29 September 2008 - 09:23 AM

Is This A Good Question/Topic? 0

## Replies To: dice guessing game

### #2 Jayman

• Student of Life

Reputation: 421
• Posts: 9,532
• Joined: 26-December 05

## Re: dice guessing game

Posted 29 September 2008 - 10:33 AM

No bother, that is what we are here for.

Glad you were able to figure out was wrong.