- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kenneth_ForquerENG_115
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Kenneth Forquer ENG 115");
这是我存储问题和答案的地方
List<Question> question = new List<Question>
{
new Question("What stage bleed air is used to start the engine?", new string[] { "8th", "9th", "1st", "13th" }, Question.multipleChoice, 2),
new Question("Igniters spark to combust the fuel.", new string[] { "true", "false" }, Question.trueAndFalse, 0),
new Question("What is the 1st stage in the cycle of the Gas turbine?", new string[] { "Intake", "Exhaust", "Power", "Combustion" }, Question.multipleChoice, 0),
new Question("What is the 3rd stage in the cycle of the Gas turbine?", new string[] { "Compression", "Combustion", "Intake", "Exhaust" }, Question.multipleChoice, 1),
new Question(" What is the last stage in the cycle of the Gas turbine?", new string[] { "Compression", "Power", "Intake", "Exhaust" }, Question.multipleChoice, 3),
new Question("Ngg refers to speed.", new string[] { "true", "false" }, Question.trueAndFalse, 0),
new Question("Npt refers to torque", new string[] { "true", "false" }, Question.trueAndFalse, 1),
new Question("What are the LM2500 metering points?", new string[] { "3", "2", "5.4", "All of the above" }, Question.multipleChoice, 3),
new Question("Which of these are a component of the compressor?", new string[] { "Inlet Plenum", "Gearbox", "Stator", "All of the above" }, Question.multipleChoice, 2),
new Question("What company manufactures the LM2500?", new string[] { "GM", "Ford", "Toyota", "Rolls Royce" }, Question.multipleChoice, 3)
};
for (int i = 0; i < question.Count; i++)
{
Console.WriteLine("--------------------------------");
Console.WriteLine("Question #" + (1 + i).ToString());
if (question[i].Ask())
{
Results.AddResult(question[i]);
Console.WriteLine("Press any key to continue to the next question.");
//Console.WriteLine("--------------------------------");
}
else
{
Results.AddResult(question[i]);
}
Console.Clear();
}
Console.WriteLine("--------------------------------");
Console.WriteLine("End of the first attempt.");
int tempScore = 0;
for (int i = 0; i < Results.firstResults.Count; i++)
{
if (Results.firstResults[i].isCorrect)
{
tempScore++;
}
}
Console.WriteLine("Your current mark is: " + tempScore + "/" + Results.firstResults.Count.ToString());
Console.WriteLine("--------------------------------");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Results.RunSecondAttemp();
Console.WriteLine("--------------------------------");
Console.WriteLine("End of the Quiz!");
int tempFinalScore = 0;
for (int i = 0; i < Results.finalResults.Count; i++)
{
if (Results.finalResults[i].isCorrect)
{
tempFinalScore++;
}
}
Console.WriteLine("Your final mark is: ");
Console.WriteLine(tempFinalScore + "/" + Results.finalResults.Count.ToString());
if (tempFinalScore > 5)
{
Console.WriteLine("Good Job!");
}
else
{
Console.WriteLine("Better luck next time...");
}
Console.WriteLine("--------------------------------");
Console.WriteLine("Press any key to exit the console...");
Console.ReadKey();
}
}
}
namespace Kenneth_ForquerENG_115
{
class Question
{
public string question;
public string[] answers;
public bool isCorrect;
public string inputAnswer;
private int correctIndex;
private string questionType;
public static string trueAndFalse = "TF";
public static string multipleChoice = "MC";
此处是问题的输入位置。
public Question(string q, string[] answersList, string typeOfQuestion, int correctAnswer)
{
question = q;
questionType = typeOfQuestion;
if (questionType == multipleChoice)
answers = new string[4];
else if (questionType == trueAndFalse)
answers = new string[2];
for (int i = 0; i < answersList.Length; i++)
{
this.answers[i] = answersList[i];
}
correctIndex = correctAnswer;
}
public bool Ask()
{
Console.WriteLine(question);
if (questionType == multipleChoice)
{
Console.WriteLine("Input an answer from the following possibilities...");
}
else
{
Console.WriteLine("Please input 'true' or 'false'... ");
}
for (int i = 0; i < answers.Length; i++)
{
Console.WriteLine(answers[i]);
}
Console.WriteLine("--------------------------------");
inputAnswer = Console.ReadLine();
if (inputAnswer == answers[correctIndex])
{
Console.Clear();
Console.WriteLine("Correct!");
isCorrect = true;
Console.WriteLine("Press any key to continue to the next question.");
Console.ReadKey();
}
else
{
Console.Clear();
Console.WriteLine("Incorrect.");
isCorrect = false;
Console.WriteLine("Press any key to continue to the next question.");
Console.ReadKey();
}
return isCorrect;
}
public void PrintQuestion()
{
Console.WriteLine(question);
if (questionType == multipleChoice)
{
Console.WriteLine("Input an answer from the following possibilities...");
}
else
{
Console.WriteLine("Please input 'true' or 'false'... ");
}
for (int i = 0; i < answers.Length; i++)
{
Console.WriteLine(answers[i]);
}
}
}
}
namespace Kenneth_ForquerENG_115
{
static class Results
{
public static List<Question> firstResults = new List<Question>();
public static List<Question> finalResults = new List<Question>();
public static void AddResult(Question questionResult)
{
firstResults.Add(questionResult);
}
public static void AddFinalResult(Question question)
{
finalResults.Add(question);
}
public static void RunSecondAttemp()
{
Console.Clear();
Console.WriteLine("Attempt #2:");
for (int i = 0; i < firstResults.Count; i++)
{
Console.WriteLine("\n--------------------------------");
Console.WriteLine("\nQuestion " + (1 + i).ToString());
if (firstResults[i].isCorrect)
{
Console.WriteLine("\nThis one was correct!");
firstResults[i].PrintQuestion();
Console.WriteLine("Your answer: " + firstResults[i].inputAnswer);
AddFinalResult(firstResults[i]);
Console.WriteLine("Press any key to continue to the next question.");
Console.ReadKey();
}
else
{
Console.WriteLine("This one was wrong on the first attempt! Please try again.");
if (firstResults[i].Ask())
{
AddFinalResult(firstResults[i]);
Console.WriteLine("Press any key to continue to the next question.");
}
else
{
AddFinalResult(firstResults[i]);
}
Console.WriteLine("\n--------------------------------");
}
Console.Clear();
}
}
}
}
基本上我想做的是让用户只能输入问题的答案。如果他们输入未列出的内容,它将显示一条错误消息,例如“输入不正确,请从给出的答案中选择”。因此,如果他们键入未列出的内容,则会出现该消息,然后返回到问题,直到他们键入选项。
最佳答案
一种选择是在检查答案是否正确之前检查他们的答案是否在答案选项中。你可以这样做:
while (Array.IndexOf(answers, inputAnswer) < 0)
{
Console.WriteLine("incorrect input, please choose from given answers.");
inputAnswer = Console.ReadLine();
}
Array.IndexOf
将返回 -1
如果inputAnswer
不在 answers
中大批。 while
在用户输入 answers
中的答案之前,循环不会中断。数组,和 inputAnswer
将包含 answers
中的答案当循环中断时。
这将放在 Ask
中包含
if (inputAnswer == answers[correctIndex])
关于c# - 我如何添加代码以使用户无法输入未列出的答案? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47426777/
(function() { main(); function main() { jQuery(document).ready(function($) {
所以我必须为我们的类(class)软件设计制作一个 GUI,我们正在为 children 制作一个游戏来练习乘法表。到目前为止,当您执行一次测试或练习时它工作正常,但是当您进行第二次运行时,它会出错。
我刚开始学习 python,想做一些琐事。基本上,我想从列表中随机询问一个问题,然后使用“输入”运算符来判断用户输入的 Y/N 是否正确。我坚持确定如何检查它是否正确。也许我的(不正确的)代码可以更好
我目前正在做一个暑期实习项目,我必须制作一个不经意的 DNS 翻译服务器。我不会在这里详细讨论被忽视的部分,但我会解释我的程序的架构。 有一个服务器端接收混淆的请求并发回一个它自己无法理解的答案。 在
我想用ajax请求翻译单词到谷歌翻译 如果我使用 curl,它会像: curl_init("http://translate.google.com/translate_a/t?client=t&tex
这是我运行dig www.google.com时的答案部分: ;; ANSWER SECTION: www.google.com. 108 IN A 74
我在ES上有以下简单数据: curl -XPUT localhost:9200/dt/art/1 -d '{ "age": 77 }' curl -XPUT localhost:9200/dt/art
我从编码开始,我有一个多维数组的示例。但它没有给出预期的答案。 我只得到“C”,我期待“JohnnyCash:Live at Folsom Prison”。出了什么问题? var music = []
我们有一个应用程序与 Crashlytic 和 Answers 配合得很好。我们需要为这个应用程序做一个不同的风格。因此,我们的 Gradle 编译工作正常,并为两个不同的品牌制作了两个不同的 APK
我正在尝试从数据库获取歌曲列表。 我在查询行中发送一个 ID 数组(永久链接),并且我希望返回值的顺序与我在数组中给出的顺序相同。有没有办法做到这一点? function getByPermalink
我有一个表单可以输入这样的值 test 有没有办法用jquery改变输入类型 我基本上想把这个添加到输入类型中 data-slider="true" data-sl
好吧,我距离数学高手还很远。哎呀,我记住了足够多的高中代数,可以拼凑出任何有效的公式,这对我来说是一个胜利。因此,如果您注意到这里有一个不必要的长或令人困惑的公式,那就可以解释了。 但是,正如人们可以
所以我的问题有点令人困惑,但仍然如此。我从外部源获取一个由 8 个字符串组成的数组,其中所有字符串都包含 double 值。这些值通常为小数点后 4 位: 12345.5678 我想做的是将其转换为小
我成功地构建了一个函数来提示用户提出问题,然后是随机排列的答案选项。但是,由于答案选择现在是随机的,python 如何识别用户输入(数字:1、2、3 或 4)以获得“正确”答案? import ran
我正在尝试使用蛮力来回答这个问题,这样我就可以理解发生了什么: https://www.interviewcake.com/question/java/product-of-other-numbers
尝试使用刚刚宣布的 Answers OSX平台框架: pod 'Fabric' pod 'Answers' pod 'Crashlytics' #import #import #import [
在我添加的页面上检索忘记的用户名 步骤 1) 输入电子邮件地址(通过电子邮件获取帐户) 第 2 步)验证安全问题(他们提供答案,我对其进行验证) 第 3 步)向他们发送带有用户名的电子邮件 第 2 步
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
在我的测试中,我需要模拟一种情况,当使用实体管理器(em)将新对象保存到数据库中时,在此过程中,该对象的id属性设置为数据库中该行的自动递增ID。我想将该id属性设置为我自己的值,以便稍后在测试中进行
我有这个代码。调用askToContinue() 方法来询问用户是否要继续,但我的问题是它只是忽略选择并重新启动程序,无论我输入什么。我在代码中遗漏了什么导致它忽略我的选择? public class
我是一名优秀的程序员,十分优秀!