Q BgQuestion:

Rookie
Karma Points: 0
Respect (100%):
posted by  ishaab on 2/11/2008 10:57:45 PM  |  status: Live  

Please help me C# program

Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
please ! can anybody help with this C# program.
Pseudocode follows:

Store secret as random 1 – 10

Get input (check for range, int, no return or illegal character)

5 tries to guess secret

Display too high or too low after wrong guesses

When program ends print either “You guessed secret in x tries” or “Sorry, too many guesses. Answer is y.”

 

Ishab

AAnswers:

Answer Question
Scholar
Karma Points: 332
posted by catherine chrysler on 2/12/2008 6:54:25 AM  |  status: Live
Asker's Rating: Lifesaver   
ishaab's comment:
"Thank you very much"
Response Details:
Don't forget  to rate my answer

using System;
using System.Collections.Generic;
using System.Text;

namespace DeleteMe
{
    class Program
    {
        static void Main(string[] args)
        {
            int rNo = (new Random()).Next(0, 9);
            int userGuessedRNO;
            int guessCount = 1;
            int allowedGuessings = 5;                        

            while (true)
            {
                System.Console.WriteLine("Please enter your guess ");              

                userGuessedRNO = Convert.ToInt32( System.Console.ReadLine() );

                if (guessCount >= allowedGuessings)
                {
                    System.Console.WriteLine("\nSorry, too many guesses. Answer is {0}", rNo);
                    break;
                }

                if (userGuessedRNO == rNo)
                {
                    System.Console.WriteLine("\nYou guessed secret in {0} tries ", guessCount);
                    break;
                }
                guessCount++;
            }
            System.Console.Read();
        }
    }
}


Copy and paste to save it into *.cs file, compile it with csc.exe (c# compiler that comes with .NET framework v2.0)
OR
Prepare c# console based application from VS studio 2005 paste the content into the main program file.  And Run it.


Answer Question
Ask New Question

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different than tutoring »