A program is required for a computer game. The user keys in the number of rounds he wishes to play.
For each round the user enters his lucky number. The program takes the number and divides it with a
secret number. If the remainder of the division is zero, it is considered a draw for the round and the total
score is incriminated by 1. Otherwise if it is any other even number, it is considered a win for the round
and the total score is incremented by 3. However if it is an odd number, it is considered a loss for the
round and the total score is decremented by 3. This is done until he completes his rounds. He wins if the
total score at the end is a positive number. Write a C# program to accomplish this.
1
Expert's answer
2018-02-23T14:35:07-0500
using System;
namespace Answer { class Program { public static void Main(string[] args) { Random random = new Random(0); int num; int Score = 0; int RoundCount = 0; int SecretNum = random.Next(0,10); RestartGame: Console.Write("Enter The Round Count: "); try { RoundCount = Convert.ToInt32(Console.ReadLine()); if (RoundCount < 0) { Console.WriteLine("The number is not supported"); goto RestartGame; } }catch(FormatException) { Console.WriteLine("You can only enter numbers"); goto RestartGame; } for(int i = 0; i < RoundCount;i++) { Console.Write("Enter The lucky number: "); try { num = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("You can only enter numbers"); goto RestartGame; }
if (Score > 0) Console.WriteLine("You won the game !!! You score: " + Score); else Console.WriteLine("You lost the game (( You score: " + Score); Console.ReadKey(); } } } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment