Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Help Cramster Blog
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

Please help me C# program

Know the answer? Have a better solution? Share it.
Sign Up Now for FREE!
Join the thousands of students
getting ahead in their classes.
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Rookie
Karma Points: 0
Respect (100%):
Date Posted: 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

Answers:

Member's Avatar

Scholar
Karma Points: 332
Date Posted: 2/12/2008 6:54:25 AM  Status: Live
Asker's Rating: Lifesaver   
Response:
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.

ishaab's Comment:
Thank you very much





By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.