Helpppp Me Plz,我不明白。 [英] Helpppp Me Plz , I Do Not Get This .

查看:68
本文介绍了Helpppp Me Plz,我不明白。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int counter = 0;
while (counter < 10)

switch(num01) 
{ case 1:
Console.WriteLine("1 * " + counter + "=" );
Console.WriteLine(num02 + num03 + num02*num03);
counter++;
break;
}







wt我想在这里做的是创建一套乘法表。对于ex: - 1 * 1 =到1 * 10 =因为我使用了计数器++ cos它使生活变得容易很多但同时我希望用户将答案放在乘法中。我不知道该怎么做。所以请帮助!!




wt i am trying to do here is to create a set of multiplication tables. for ex:- " 1*1=" to "1*10 = " for that i have used counter ++ cos it makes life a lot easier but at the same time i want the user to put the answers to the multiplications . n i dnt know how to do that . so please help!!

推荐答案

[更新]

我意识到我忘了将Console.ReadLine的返回值从string转换为整数。



你可以先询问用户他/她想要使用哪个表格1 - 10。

[UPDATE]
I realized that I forgot to convert the return value from Console.ReadLine from string to integer.

You could start with asking the user which table, 1 - 10, he/she wants to use.
Console.WriteLine("Enter the number for the multiplication table (1 - 10)");
string input = Console.ReadLine();
int tableNumber = 0;
if (!int.TryParse(input, out tableNumber)
{
    Console.WriteLine("The entered value is not a number.");
    // TODO: Add error handling
}



在控制台应用程序中,更容易编写问题并直接读取用户输入而不是编写所有问题,然后阅读用户输入。

(要做到这一点,你是最好使用Windows窗体项目)

正如Garth在你的问题的评论中所说,在这种情况下,for循环更喜欢,因为你有一个已知的迭代次数。

但是,如果您希望用户在不正确的情况下重复答案,可以使用while循环。


In a console application it is easier to write the question and read the user input directly instead of writing all the questions and then read the user input.
(To do that you are better off using a Windows Form project)
As Garth said in the comment to your question, in this case a for-loop is to prefer as you have a known number of iterations.
However, if you want the user to repeat the answer if it is not correct, a while loop can be used.

int answer = 0;
int index = 0;
while (index < 10)
{
    Console.Write("{0} x {1} = ", tableNumber, index + 1);
    input = Console.ReadLine();
    if (int.TryParse(input, out answer)
    { 
        // TODO: Check if answer is correct
        if (answer == ?) // TODO: Replace the question mark with an expression
            index++;     // Only increment the index if the answer is correct.
    }
    else
    {
        Console.WriteLine("The entered value is not a number.");
    }
}



然后你可以添加用户可以通过按Escape来随时中断循环。



这不是一个完整的解决方案,你必须自己做一些工作,但这应该是一个好的开始。

此外,这只是一种方法。


Then you can add that the user can break the loop at any time by pressing Escape, for example.

This is not not a complete solution, you have to do some work yourself, but it should be a good start.
Also, this is only one way to do it.


这篇关于Helpppp Me Plz,我不明白。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆