ここで簡単なクイズを作成しようとしていますが、ユーザーがどのように入力しても、間違っていても、ユーザーには常に正しい答えがあると言われます。
これが私のソースコードです:ここに表示される最初のクラスはProgram.csです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TheQuiz
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to the Quiz! \nYou'll be asked 20 questions! If you get one question wrong, you'll be out.\nHowever if you answer all 20 questions correctly, you'll be the MASTER!");
Console.WriteLine("\nLet us begin! Are you ready?\n\n");
Console.WriteLine("(Remember, TYPE in the correct answer. Every answer has ONE word only!\nAnd ALWAYS use a capital letter at the beginning of the answer: 'Answer')\n\n(Press Enter to continue...)");
Console.ReadKey();
Console.Clear();
Console.WriteLine("In what country was Adolf Hitler born?");
Console.ReadLine();
if (Answers.AnswerOne.Equals("Austria"))
{
Console.WriteLine("Congratulations! {0} is the correct answer!", Answers.AnswerOne);
}
else if (!Answers.AnswerOne.Equals(Answers.AnswerOne))
{
Console.WriteLine("Sorry! You wrote the wrong answer!\nThe correct answer was {0]", Answers.AnswerOne);
}
Console.ReadKey();
}
}
}
これが私の他のクラス、Answers.csです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TheQuiz
{
public class Answers
{
public static string AnswerOne = "Austria";
public static string AnswerTwo = "";
public static string AnswerThree = "";
public static string AnswerFour = "";
public static string AnswerFive = "";
public static string AnswerSix = "";
public static string AnswerSeven = "";
public static string AnswerEight = "";
public static string AnswerNine = "";
public static string AnswerTen = "";
public static string AnswerEleven = "";
public static string AnswerTwelve = "";
public static string AnswerThirteen = "";
public static string AnswerFourteen = "";
public static string AnswerFifteen = "";
public static string AnswerSixteen = "";
public static string AnswerSeventeen = "";
public static string AnswerEighteen = "";
public static string AnswerNineteen = "";
public static string AnswerTwenty = "";
}
}
したがって、正解はオーストリアですが、ユーザーがドイツのような他の何かを入力した場合でも、それが正解であることを示しています。
前もって感謝します。