Question

In: Computer Science

Assignment Description Write a program that will have a user guess whether a person is a...

Assignment Description

Write a program that will have a user guess whether a person is a musician or a writer. You will create a

group of four names, two musicians and two writers, and show the user a name randomly selected from

the four. The user will then guess whether they think the name belongs to a musician or writer. After a

guess, the program will tell the user whether they are correct, repeat the name, and reveal the correct

answer.

Tasks

1) The program needs to contain the following

a.

A comment header containing your name and a brief description of the program

b. At least 5 comments besides the comment header explaining what your code does

c.

Four string variables, two musicians and two writers

d. A way to randomly display one of the four names to the user

e. Output asking the user whether the name displayed is a musician or a writer

i. If the user guesses correctly, congratulate them before outputting the displayed

name and the correct answer

ii. If the user guesses incorrectly, output the displayed name and the correct

answer

f.

“Press enter to continue” and Console.Read(); at the end of your code

2) Upload the completed .cs file onto the Assignment 3 submission folder. To access the .cs file:

a.

Right click on your program tab

b. Click “Open containing folder”

c.

The file you are working on will be there with a .cs extention, upload the .cs file


please code in C#- (C Sharp)

Solutions

Expert Solution

Answer:

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] selectNames = { "Alex", "Ryan", "Alice", "Rebecca" }; //array to store the names
            string[] selectProfession = { "Musician", "Writer" }; //array to store the profession
            string Name = null;
            string Profession=null;
            string readInput;

            Random r = new Random(); //Random class is used to generate a name and profession randomly

            int index = r.Next(selectNames.Length); //stores the index of the randomly selected name
            int index2 = r.Next(selectProfession.Length); //stores the index of the randomly selected profession

            Name = selectNames[index]; //stores the random name in a name variable of type string

            //checks for each name in array and assigns a random profession to each of them
            if (Name == "Alex")
                Profession = selectProfession[index2];

            else if (Name == "Ryan")
                Profession = selectProfession[index2];

            else if (Name == "Alice")
                Profession = selectProfession[index2];

            else if (Name == "Rebecca")
                Profession = selectProfession[index2];

            //Displays a name randomly to the user and asks them guess the person's profession
            Console.WriteLine("Guess whether the following person is musician or writer:");
            Console.WriteLine("Name: " + Name + "\n");
            Console.WriteLine("User's Turn ");
            Console.WriteLine("Guess whether "+ Name + " is a musician or writer:");
            readInput = Console.ReadLine(); //stores the userInput in a string variable

        
            //if user input is equal to the profession of the person then you win else you lose
            if (readInput.Equals(Profession))
            {
                Console.WriteLine("Congratulations...!! \nYou have guessed the profession correctly");
                Console.WriteLine("Name: " + Name + "\nProfession: " + Profession);
            }

            else
            {
                Console.WriteLine("Uh oh...!! \nYour guess was incorrect\nCorrect Guess is:");
                Console.WriteLine("Name: " + Name + "\nProfession: " + Profession);
            }

            Console.WriteLine("\n\nPress Enter to continue");
            Console.Read();

          
        }
    }
}


Output:


Related Solutions

Write a program called whilebun.py, in which the user is asked to guess the name of...
Write a program called whilebun.py, in which the user is asked to guess the name of your favorite DBVac vacuum cleaner model. Your program should: · Include a comment in the first line with your name. · Include comments describing each major section of code. · Set a variable called vacname to be equal to the name of your favorite DBVac vacuum cleaner model. · Ask the user to guess the name. Allow the user to make up to three...
In Java: Write a program that generates a random number and asks the user to guess...
In Java: Write a program that generates a random number and asks the user to guess the number and keeps track of how many guesses it took If the user input is negative or zero then the loop must stop reading further inputs and display how many guesses they used If they guess the correct number display a message telling them they got it and exit the program If they guess the wrong number (but still a legal guess) you...
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
17. Write a program that generates a random number and asks the user to guess what...
17. Write a program that generates a random number and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. 18. Enhance the program that you wrote for Programming...
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close Do you...
Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
In C Programming, Thanks Many user-created passwords are simple and easy to guess. Write a program...
In C Programming, Thanks Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string. You may assume that the string does not contain spaces and will always contain less than 50 characters. i becomes ! a becomes @ m becomes M B becomes 8 o becomes . Ex: If the input...
Write a program that checks whether or not a date entered in by the user is...
Write a program that checks whether or not a date entered in by the user is valid. Display the date and say if it is valid. If it is not valid explain why. The input may be in the format mm/dd/yyyy, m/d/yyyy, mm/d/yyyy, or m/dd/yyyy. A valid month (mm) must be from 1 to 12 A valid day (dd) must be from 1 to the appropriate number of days in the month April, June, September, and November have 30 days...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT