我需要在C#中为School进行一个简单的3个问题测验.我需要帮助找出如何解决我的错误. [英] I need to make a simple 3 question quiz for School in c#. I need help finding out how to fix my mistakes.
问题描述
首先是我整理在一起的糟糕代码:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
命名空间ConsoleApplication5
{
课程计划
{
静态void Main(string [] args)
{
Console.WriteLine(什么是9 + 10&");
Console.WriteLine("A)19");
Console.WriteLine("B)21");
Console.ReadLine();
{
{
if(Console.ReadLine()=="A)19")
Console.WriteLine(您以为您很聪明吗");
其他
{
Console.WriteLine(您是白痴");
}
Console.WriteLine(哪个词最能说明循环?");
Console.WriteLine("A)Itteration");
Console.WriteLine("B)Banana");
Console.ReadLine();
{
如果(Console.ReadLine()=="A)迭代")
Console.WriteLine(不错=/");
其他
{
Console.WriteLine(您不应将此事告诉任何人"));
}
Console.WriteLine(当您有两个参数方程式时,可以用来计算dy/dx的规则的名称是什么?");
Console.WriteLine("A)替换规则");
Console.WriteLine("B)Chain rule");
Console.ReadLine();
{
if(Console.ReadLine()==("B)Chain rule"))
Console.WriteLine("I r8 8/8");
其他
{
}
}
}
}
}
}
}
}
现在我的问题是当我输入问题的答案时,我不知道如何让控制台识别我的输入,如果按回车键,它只会显示我设置的else消息.能否请大家指出我哪里出了问题.
-感谢
Hi,
first off here is the terribly written code I have mangled together:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What is 9+10");
Console.WriteLine("A)19");
Console.WriteLine("B)21");
Console.ReadLine();
{
{
if (Console.ReadLine() == "A)19")
Console.WriteLine("You think you are so smart don't you");
else
{
Console.WriteLine("You are an idiot");
}
Console.WriteLine("Which word best descibes a loop?");
Console.WriteLine("A)Itteration");
Console.WriteLine("B)Banana");
Console.ReadLine();
{
if (Console.ReadLine() == "A)Itteration")
Console.WriteLine("not bad =/");
else
{
Console.WriteLine("You shouldn't tell anyone about this");
}
Console.WriteLine("When you have two parametric equations, what's the name of the rule you can use to work out dy/dx?");
Console.WriteLine("A)Substitution rule");
Console.WriteLine("B)Chain rule");
Console.ReadLine();
{
if (Console.ReadLine() == ("B)Chain rule"))
Console.WriteLine("I r8 8/8");
else
{
}
}
}
}
}
}
}
}
Now my problem is I have no idea how to get the console to recognize my input when i type the answers to the questions and it just gives me the else message I set if I press enter. Can you all point out where I have went wrong please.
-Thanks
推荐答案
您必须将Console.Readline的输出分配给如下所示的变量
You have to assign the output of your Console.Readline to a variable like the below
String Answer = "";
Answer = Console.ReadLine();
{
{
if (Answer == "A)19")
Console.WriteLine("You think you are so smart don't you");
else
{
Console.WriteLine("You are an idiot");
}
所以您的程序变成了
using System;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What is 9+10");
Console.WriteLine("A)19");
Console.WriteLine("B)21");
String Answer = "";
Answer = Console.ReadLine();
{
{
if (Answer == "A)19")
Console.WriteLine("You think you are so smart don't you");
else
{
Console.WriteLine("You are an idiot");
}
Console.WriteLine("Which word best descibes a loop?");
Console.WriteLine("A)Itteration");
Console.WriteLine("B)Banana");
Answer = "";
Answer = Console.ReadLine();
{
if (Answer == "A)Itteration")
Console.WriteLine("not bad =/");
else
{
Console.WriteLine("You shouldn't tell anyone about this");
}
Console.WriteLine("When you have two parametric equations, what's the name of the rule you can use to work out dy/dx?");
Console.WriteLine("A)Substitution rule");
Console.WriteLine("B)Chain rule");
Answer = "";
Answer = Console.ReadLine();
{
if (Answer == ("B)Chain rule"))
Console.WriteLine("I r8 8/8");
else
{
}
}
}
}
}
}
}
}
这篇关于我需要在C#中为School进行一个简单的3个问题测验.我需要帮助找出如何解决我的错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!