Number Guessing Game.  The program will generate a random number from 1 to 1000.  The player will be given several chances to guess the number.  The program gives a hint that the given number is lower or higher. If the player's guess is correct, give the player a single point. Tally the number of correct and wrong guesses that the player has made. After every round, display the tally (correct, wrong, and score)  After a cycle the program will ask the user if he wants to continue playing. This is a console project.   Below source code is my answer with the Question. Kindly check it sir/maam if i have the problem with the code. Thank you using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { while (true) { int randno = Newnum(1, 1001); int count = 1; while (true) { Console.Write("Enter a number between 1 and 1000(0 to quit):"); int input = Convert.ToInt32(Console.ReadLine()); if (input == 0) return; else if (input < randno) { Console.WriteLine("Low, try again."); ++count; continue; } else if (input > randno) { Console.WriteLine("High, try again."); ++count; continue; } else { Console.WriteLine("You guessed it! The number was {0}!", randno); Console.WriteLine("It took you {0} {1}.\n", count, count == 1 ? "try" : "tries"); break; } } } } static int Newnum(int min, int max) { Random random = new Random(); return random.Next(min, max); } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question
100%

 

Number Guessing Game.

  1.  The program will generate a random number from 1 to 1000.
  2.  The player will be given several chances to guess the number.
  3.  The program gives a hint that the given number is lower or higher.
  4. If the player's guess is correct, give the player a single point.
  5. Tally the number of correct and wrong guesses that the player has made.
  6. After every round, display the tally (correct, wrong, and score)
  7.  After a cycle the program will ask the user if he wants to continue playing.

This is a console project.

 

Below source code is my answer with the Question. Kindly check it sir/maam if i have the problem with the code. Thank you

using System;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main(string[] args)
{
while (true)
{
int randno = Newnum(1, 1001);
int count = 1;
while (true)
{
Console.Write("Enter a number between 1 and 1000(0 to quit):");
int input = Convert.ToInt32(Console.ReadLine());
if (input == 0)
return;
else if (input < randno)
{
Console.WriteLine("Low, try again.");
++count;
continue;
}
else if (input > randno)
{
Console.WriteLine("High, try again.");
++count;
continue;
}
else
{
Console.WriteLine("You guessed it! The number was {0}!",
randno);
Console.WriteLine("It took you {0} {1}.\n", count,
count == 1 ? "try" : "tries");
break;
}
}
}

}
static int Newnum(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage