1 Replies - 2511 Views - Last Post: 29 September 2008 - 10:33 AM Rate Topic: -----

#1 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • 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
                {
                    input = Console.ReadLine();
                    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.");
                guessStr = Console.ReadLine();
                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  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1