Question: Create a C# program in visual studios called FortuneCookie whose Main() method contains an array of at least 8 strings with fortune-telling phrases. The program

Create a C# program in visual studios called FortuneCookie whose Main() method contains an array of at least 8 strings with fortune-telling phrases. The program should randomly select 2 different phrases and pass them to a method that displays them. A random number generator should be used to select the phrases from random positions in the array and the length of the array should be used to determine one of the random number generator range boundaries (i.e., do not hardcode a number for the range boundary).

The output should look something like this:

Do you want me to read your fortune? y

Your fortune says:

You will travel to faraway lands.

You are wise beyond your years.

This is what I have so far.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace FortuneCookie { class Program { static void Main() { string[] myArray = new string[]

{ "There will be some money coming your way soon.", "You will travel to faraway lands.","Happiness is just around the corner.","You are wise beyond you years.", "The number 3 is very significant for you.", "I see a tall dark, and handsome stranger in your future.","Lots of suprises are waiting for you.","You'll be getting that promotion you wanted." };

Random r = new Random();

int s1 = r.Next(myArray.Length);

int s2 = r.Next(myArray.Length);

while(s1 == s2);

{

s2 = r.Next(myArray.Length);

}

Display(myArray[s1], myArray[s2]);

}

public static void Display(string str1, string str2)

{

Console.WriteLine("Your fortune says: ");

Console.WriteLine(str1);

Console.WriteLine(str2); }

} } I'm having trouble figuring out how to add the question "Do you want me to read your fortune y/n? " to the program allowing the user to enter y or n for the anwser. If y compile the program but if n exit the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!