In: Computer Science
PLEASE DO THIS IN C#: Back in my Day! Kids who grew up in the late 70s didn’t have a lot of options for video games, but they did have “Choose your own Adventure” books. These books were cool and let the reader make meaningful decisions. If they chose choice “A”, they would turn to a page of the book and continue their adventure. If they chose choice “B”, they would turn to a different page and read a different adventure. Your task is to design (pseudocode) and implement (source code) for a story that has four different outcomes based on two different user inputs. See appendix for checking string equality. Sample run 1: It is a dark and stormy night. Do you want to take an umbrella? (Y/N): Y Good - you have an umbrella. You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your umbrella or run? ((F)ight/(R)un): F You take out your umbrella and jab it into the wolf's paw! It runs away and you live another day. Sample run 2: It is a dark and stormy night. Do you want to take an umbrella? (Y/N): Y Good - you have an umbrella. You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your umbrella or run? ((F)ight/(R)un): R You begin running so fast, the umbrella opens and you fly away like Mary Poppins. You're a little embarrassed, but you see the wolf fading off in the distance. Sample run 3: It is a dark and stormy night. Do you want to take an umbrella? (Y/N): N You decide not to take an umbrella. You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your hands or run? ((F)ight/(R)un): F You begin fighting the wolf only to realize you had just eaten a McGrease® meal earlier. You fall dead from rigorous exercise, having had a heart attack.
Pseudocode:
This program continues a story according to the user's input
In the main function
print prompt "It is a dark and stormy night. Do you want to take an umbrella? (Y/N):"
Label bose:
Take the input from user
if user input is equal to string Y
then print prompt "Good - you have an umbrella. You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your umbrella or run? ((F)ight/(R)un):"
label tagore:
Take the input from user
if user input is equal to string F
then print prompt "You take out your umbrella and jab it into the wolf's paw! It runs away and you live another day."
else if user input is equal to string R
then print prompt " You begin running so fast, the umbrella opens and you fly away like Mary Poppins. You're a little embarrassed, but you see the wolf fading off in the distance."
else
then print prompt "!!ERROR!! PLEASE ENTER F/R"
passing control to the label tagore.
else if user input is equal to string N
then print prompt "You decide not to take an umbrella. You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your hands or run? ((F)ight/(R)un)"
label tagore:
Take the input from user
if user input is equal to string F
then print prompt "You begin fighting the wolf only to realize you had just eaten a McGrease® meal earlier. You fall dead from rigorous exercise, having had a heart attack."
else if user input is equal to string R
then print prompt "You were unable to outrun the wolf and he enjoyed his meal"
else
then print prompt "!!ERROR!! PLEASE ENTER F/R"
passing control to the label tagore.
else
then print prompt "!!ERROR!! PLEASE ENTER Y/N"
passing control to the label bose.
*****************C# code******************
using System;
namespace Story
{
public class Storygame
{
public static void Main(string[] args)
{
String c; // declaring string variable
Console.WriteLine("It is a dark and stormy night. Do you want to
take an umbrella? (Y/N):"); //output on console
bose: //label
for goto command for bose
c = Console.ReadLine(); //storing input in c variable
if(Equals(c,"Y")) //checking equality of the strings
{
Console.WriteLine("Good - you have an umbrella. You start to walk
down a path and hear a scream. You realize that the person
screaming is YOU because you see a wolf! Do you fight with your
umbrella or run? ((F)ight/(R)un):");
tagore: //label for goto command for tagore
c=Console.ReadLine(); //storing input in c variable
if(Equals(c,"F"))
Console.WriteLine(" You take out your umbrella
and jab it into the wolf's paw! It runs away and you live another
day.");
else if(Equals(c,"R"))
Console.WriteLine(" You begin
running so fast, the umbrella opens and you fly away like Mary
Poppins. You're a little embarrassed, but you see the wolf fading
off in the distance.");
else
{
Console.WriteLine("!!ERROR!!
PLEASE ENTER F/R");
goto tagore; //reverting back
to label tagore using goto keyword
}
}
else
if(Equals(c,"N"))
{
Console.WriteLine("You decide not to take an
umbrella. You start to walk down a path and hear a scream. You
realize that the person screaming is YOU because you see a wolf! Do
you fight with your hands or run? ((F)ight/(R)un)");
tagore:
c=Console.ReadLine();
if(Equals(c,"F"))
Console.WriteLine("You begin
fighting the wolf only to realize you had just eaten a McGrease®
meal earlier. You fall dead from rigorous exercise, having had a
heart attack.");
else if(Equals(c,"R"))
Console.WriteLine("You were
unable to outrun the wolf and he enjoyed his meal");
else
{
Console.WriteLine("!!ERROR!!
PLEASE ENTER F/R");
goto tagore;
}
}
else
{
Console.WriteLine("!!ERROR!!
PLEASE ENTER Y/N");
goto bose; //reverting back
to label bose using goto keyword
}
}
}
}
Output:
**********NOTE**********
we use goto command for control passing(advised to be not used in complex project)
Equals(c,"R")- equals here is being used
In C#,
Equals(String,
String) is a String method to
compare strings
******** If this answer helps YOU PLEASE LIKE ThankYou********
It is a dark and stormy night. Do you want to take an umbrella? (Y/N): Good you have an umbrella. You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your umb F You take out your umbrella and jab it into the wolf's paw! It runs away and you live another day