Answer to Question #174248 in C# for Kwame Hayford

Question #174248

Question 1

A) Write a game entirely in shell script which generates an unknown number and prompts the player to enter a number. Your game should receive the number and compare it to the generated number, let your game tell the player whether the number entered is higher than or lower than the hidden number until the player is able guess the number or quit the game, upon guessing the right number the game should congratulate the player for winning and tell the player how many attempts were made before guessing the right number.


B) Write a shell script that uses a function to count the number of files in the present working directory and output their number to the screen.


 C)Explain with examples how to make variables available to child processes/shells


D) Many beginners are confused about the difference between the working of touch and of cat, could you please make the difference clear with an example


1
Expert's answer
2021-03-25T17:02:21-0400

A)

using System;

namespace Game
{
    class Program
    {
        public static void Main(string[] args)
        {
            Random rnd = new Random();
            int random_n = rnd.Next(0,100);
            int n = -1;
            int count = 0;
            do
            {
                Console.Write("Enter a number from 0 to 100: ");
                try
                {
                    n = Convert.ToInt32(Console.ReadLine());
                }
                catch(Exception)
                {
                    Console.WriteLine("Error");
                    continue;
                }
                count++;
                if(n > random_n)
                    Console.WriteLine("the number is greater than the hidden one");
                else if(n < random_n)
                    Console.WriteLine("the number is less than the hidden one");
                else 
                {
                    Console.WriteLine("You've won! Number of attempts = " + count);
                }
            }
            while(n != random_n);
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}


B)

using System;
using System.IO;

namespace Test
{
    class Program
    {
        public static void Main(string[] args)
        {
            
            string dir = "C:\\Windows\\";
 
            if (Directory.Exists(dir))
                Console.WriteLine(Directory.GetFiles(dir).Length);
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}


C)

//unavailable variables:
int a;
string s;

//available variables:
public int a;
public string s;


D)

touch file - create a file
cat file - view the contents of a file

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS