C#: Create a scenario, using something to do with sports, where the console/comp
ID: 3753902 • Letter: C
Question
C#:
Create a scenario, using something to do with sports, where the console/computer gives the user a set of clues that lead to a correct answer about the topic matter, where only one answer will work. For example, if the answer is “beach,” a clue could be “this is a place with sand and water.”
The answer must be a one word answer, and the first letter must be a capital letter (Ex: Beach, Water, Jacob)
The console/computer must check for capital letters.
The console/computer must tell the user if the answer is correct or incorrect and tell it something when those happen as well. (Ex: You are correct ! Thank you for answering this question OR This is incorrect, Please try again)
This must be in a loop until the user gets the correct answer.
Keep in mind if you are looking for “Orlando” as the answer, but the user types in “orlando,” the answer is not wrong or incorrect, it just needs a capital letter. So, be specific in what you tell your users...any mistake can make a user stop using your app or think it is broken.
Also keep in mind, if you are looking for “Miami” as the answer, but the user types in “Tampa,” and you tell them they are wrong, and wait for the answer again and again, that does not help the user get the correct answer...try giving tips, clues, letters to the word, ask the question in a different way, etc.
Explanation / Answer
According to your question we need to use Dictionary here so that we can store the Key, Value pair here:
Key: Answer & Value: Clues
The program will be:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample
{
class Program
{
public IDictionary<string, string> Dict = new Dictionary<string, string>();
public IDictionary<string, string> Hint = new Dictionary<string, string>();
public Program()
{
}
public void addAnsClue(string ans, string clue)
{
Dict.Add(ans, clue);
}
public void addHint(string clue, string hint)
{
if (Dict.Values.Contains(clue))
{
Hint.Add(clue, hint);
}
}
static void Main(string[] args)
{
Program p = new Program();
//To add Clues and Answers Manually
p.addAnsClue("Beach", "this is the place with sand and water.");
//To add Hints for Clues Manually
p.addHint("this is the place with sand and water.", "Sand & Water");
p.addAnsClue("Miami", "this is the place with white sand and nightclubs.");
//getting all the clues
var clues = p.Dict.Values.ToArray();
string ans;
int count = 0;
do
{
//printing the first clue
Console.WriteLine("Clue is:{0}", clues[0]);
Console.WriteLine("---------------------------------------");
Console.WriteLine("Enter the answer (First Letter Capital):");
ans = Console.ReadLine();
string found;
if (p.Dict.TryGetValue(ans, out found) && found == clues[0])
{
Console.WriteLine("Congrats correct answer.... ");
break;
}
else
{
Console.WriteLine("Please try again.. & Please use first letter capital for your answer.... ");
count++; //count for no of wrong attempts
//providing hints to user if user has entered wrong answer 3 times
if (count == 3)
{
Console.WriteLine("Hints: {0} ", p.Hint[clues[0]]);
}
}
} while (ans != null);
Console.ReadLine();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.