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); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education