Question

==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...

==Modify the M8B by using C#==

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace M8B

{

    class Magic8Ball

    {

        static void Main(string[] args)

        {

            string question;

            Console.WriteLine("I am the Magic 8-ball! Ask me a question and I will give you an answer.");

            Console.Write("Your question: ");

            question = Console.ReadLine();

            Console.WriteLine("\nLet me part the mists of the time for you.");

            Random rnd = new Random();

            int roll = rnd.Next(1, 5);

            if (roll == 1)

            {

                Console.WriteLine("Answer: It is certain");

            }

            else if (roll == 2)

            {

                Console.WriteLine("Answer: Reply hazy, Try Again");

            }

            else if (roll == 3)

            {

                Console.WriteLine("Answer: Don’t count on it");

            }

            else if (roll == 4)

            {

                Console.WriteLine("Answer: Signs point to yes");

            }

            else

            {

                Console.WriteLine("Answer: My sources say no");

            }

            Console.Write("\nPress any key to continue. . .");

            Console.ReadKey();

        }

    }

}

=====

Use a loop to let the user ask additional questions.

Ask a simple yes or no question whether they would like to continue.

If ‘y’ for yes, loop should allow another question to be asked and give them another answer.

If ‘n’ for no, then your loop should end.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In case of any query do comment. Please rate answer. Thanks

Code:

using System;

namespace M8B

{

    class Magic8Ball

    {

        static void Main(string[] args)

        {

            string question, choice;

            Console.WriteLine("I am the Magic 8-ball! Ask me a question and I will give you an answer.");

            //do while loop till user enters Y

            do

            {

                Console.Write("Your question: ");

                question = Console.ReadLine();

                Console.WriteLine("\nLet me part the mists of the time for you.");

                Random rnd = new Random();

                int roll = rnd.Next(1, 5);

                if (roll == 1)

                {

                    Console.WriteLine("Answer: It is certain");

                }

                else if (roll == 2)

               {

                    Console.WriteLine("Answer: Reply hazy, Try Again");

                }

                else if (roll == 3)

                {

                    Console.WriteLine("Answer: Don’t count on it");

                }

                else if (roll == 4)

                {

                    Console.WriteLine("Answer: Signs point to yes");

                }

                else

                {

                    Console.WriteLine("Answer: My sources say no");

                }

                Console.Write("\nDo you want to continue. Enter Y for Yes and N for No: ");

                choice = Console.ReadLine();

            } while (choice == "Y" || choice == "y");

            Console.Write("\nPress any key to continue. . .");

            Console.ReadKey();

        }

    }

}

Output:

Add a comment
Know the answer?
Add Answer to:
==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Could anybody give me comment here to help me understand this code? please, I want details...

    Could anybody give me comment here to help me understand this code? please, I want details comment. thank you in advance using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Framing { class Program { static void Main(string[] args) { Dictionary charEncoding = new Dictionary(); charEncoding.Add("A", "01000111"); charEncoding.Add("B", "11100011"); charEncoding.Add("C", "11000001"); charEncoding.Add("ESC", "11100000"); charEncoding.Add("FLAG", "01111110"); Console.WriteLine("Enter Sequence: "); string input = Console.ReadLine().Trim().ToUpper(); Console.Write("Byte count: " + Convert.ToString((input.Split(' ').Length + 1), 2).PadLeft(8, '0')); foreach (string str in input.Split(' '))...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • I am writing a console application in C#. It is a receipt where the user inputs...

    I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop...

  • Fix the code using C# shown below to show the repitition as seen on the example...

    Fix the code using C# shown below to show the repitition as seen on the example screenshot: (Invalid error must repeat): using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program { class Program { static void Main(string[] args) { double num, count = 0; double Tax = 0.00, ship = 5.00, sum = 0.00; double grandtotal; char line; //Set run =true bool run=true; do { //read amount of item Console.WriteLine("What is the amount of item : "); //read in...

  • [C#] I need to convert this if/else statements into Switch I have the code for the...

    [C#] I need to convert this if/else statements into Switch I have the code for the if/else but now need to turn it into a switch. The Console.WriteLine and all that is fine. I just need to convert the if/else.      int x1, x2, y1, y2;                 Console.WriteLine("What is smallest value of x:");                 x1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is largest value of x:");                 x2 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is smallest value of y:");                 y1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is largest value of y:");                 y2 =...

  • C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that...

    C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that line N times. That is, output a square of N lines each with N characters. Example output for parameters N=5 and S="*" should appear as follows: 多多本事事 串串串串串 事事事串串 事事事事事 2. Modify the DrawChars method so that the number of the line appears at that position within the line. That is, line i must have N-1 copies of S with the additional character in...

  • Greetings everyone I am having a little trouble with this one. I bolded my switch case...

    Greetings everyone I am having a little trouble with this one. I bolded my switch case which should work but its currently not. If a user selected course option 1 twice it just says you enrolled in course 1 and course 1. It should stop it by executing case -2. Need a new set of eyes. - Thanks using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleRegisterStudent { class Program { static void Main(string[] args) { (new...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • I'm attempting to convert the Board and CheWin sections into classes. Is there a way to...

    I'm attempting to convert the Board and CheWin sections into classes. Is there a way to do just that? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace TicTacToe { class TicTacToe { static char[] arr = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; static int player = 1; static int choice; static int flag = 0; static void Main(string[] args) { do { Console.Clear(); Console.WriteLine("Player 1 : 'X' \nPlayer 2...

  • C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT