C#Console.Clear问题。 [英] C# Console.Clear Problem.

查看:82
本文介绍了C#Console.Clear问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



问题1:请帮助我,我正在尝试用C#进行测验程序。但是当我使用Consol.clear()时我得到一个小问题然后所有数据都将被删除,但我想删除特定区域。因为当所有控制台清除然后得分值自动重置为(0)。而我不想要这个。



i想要在下一个问题得分值自动增加或减少根据相同的给定条件。



问题2:当用户输入问题1的答案时,光标位置保持打开状态顶部但我希望它像问题一样自动进入同一个地方。



请帮助我如果有人知道这个



代码



<前lang =cs> int x;
Console.SetCursorPosition( 57 2 );
Console.Write( 得分:);
Console.Write( \ n \ nQ:巴基斯坦国家Gmae是......? );
Console.Write( \ n\\\
1:Cricket.\\\
\\\
2:Hockey .\\\
\\\
3:Basketball.\\\
\\\
4:无);
Console.Write( \ n\\\
Choice:
);
x = Convert.ToInt16(Console.ReadLine());
if (x == 1
{
Console。 SetCursorPosition( 65 2 );
Console.WriteLine( {0},总计+ 1);
}
else if (x!= 1
{
Console.WriteLine( {0} ,total--);
}
console.clear();
Console.Write( \ n \ nQ:澳大利亚国家Gmae是......? );
Console.Write( \ n\\\
1:Cricket.\\\
\\\
2:Hockey .\\\
\\\
3:Basketball.\\\
\\\
4:无);
Console.Write( \ n\\\
Choice:
);
if (x == 1
{
Console。 SetCursorPosition( 65 2 );
总计=总计+ 2 ;
Console.WriteLine( {0},total);
}
else if (x!= 1
{
Console.WriteLine( {0} ,total--);
}
Console.ReadLine();

解决方案

阅读原始MSDN文档有什么问题? http://msdn.microsoft.com/en- us / library / system.console.clear%28v = vs.110%29.aspx [ ^ ]。



我想,写作无论如何,这样的应用程序是应用程序中最糟糕的想法之一。



-SA


我希望相信,你正在为学术兴趣编写这个程序:-)



你的代码有很多问题......有些问题排在下面。检查这是否有帮助。写一些代码,再做一些实验并阅读更多代码。如果你还有问题,请回来



  int  x; 
int total = 0 ;
Console.SetCursorPosition( 57 2 );
Console.Write( 得分:);
Console.Write( \ n \ nQ:巴基斯坦国家Gmae是......? );
Console.Write( \ n\\\
1:Cricket.\\\
\\\
2:Hockey .\\\
\\\
3:Basketball.\\\
\\\
4:无);
Console.Write( \ n\\\
Choice:
);
x = Convert.ToInt16(Console.ReadLine());
if (x == 1
{
Console。 SetCursorPosition( 65 2 );
Console.WriteLine( {0},total + 1 );
}
else if (x!= 1
{
Console.WriteLine( {0} ,total--);
}
Console.SetCursorPosition( 1 2 );

Console.Write( \ n \ nQ:澳大利亚国家Gmae是.. ?..);
Console.Write( \ n\\\
1:Cricket.\\\
\\\
2:Hockey .\\\
\\\
3:Basketball.\\\
\\\
4:无);
Console.Write( \ n\\\
Choice:
);
Console.CursorLeft = Console.CursorLeft - 2 ;
x = Convert.ToInt16(Console.ReadLine());
if (x == 1
{
Console。 SetCursorPosition( 65 2 );
总计=总计+ 2 ;
Console.WriteLine( {0},total);
}
else if (x!= 1
{
Console.SetCursorPosition( 65 2 < /跨度>);
Console.WriteLine( {0},total--);
}
Console.ReadLine();





干杯


Hello Everyone!

Q 1:Please Help Me i am Trying to make Quiz Program in C# . but i get a little problem when i used Consol.clear() then all data will be delete but i want to delete Specific Area. Because when all Console Clear Then Score Value Automatically Reset To (0).and i did not want this .

i want in the Next Question Score Value Automatically Increase or Decrease According to The Given Condition.on The Same Give Position.

Q 2:When user Enter The Answer Of Question one Then Cursor Position Remain On The Top But i want that it Automatically Come On The Same Place Like Question One.

Please Help me If Any one know about this

code

 int x;
Console.SetCursorPosition(57, 2);
Console.Write("Score:");
Console.Write("\n\nQ:Pakistan National Gmae Is....?");
Console.Write("\n\n1:Cricket.\n\n2:Hockey.\n\n3:Basketball.\n\n4:None.");
Console.Write("\n\nChoice:");
x = Convert.ToInt16(Console.ReadLine());
if (x == 1)
{
    Console.SetCursorPosition(65, 2);
    Console.WriteLine("{0}", total+1);
}
else if (x!= 1)
{
  Console.WriteLine("{0}",total--);
}
 console.clear();
Console.Write("\n\nQ:Australia National Gmae Is....?");
Console.Write("\n\n1:Cricket.\n\n2:Hockey.\n\n3:Basketball.\n\n4:None.");
Console.Write("\n\nChoice:");
if (x == 1)
{
    Console.SetCursorPosition(65, 2);
    total = total + 2;
    Console.WriteLine("{0}", total);
}
else if (x != 1)
{
    Console.WriteLine("{0}", total--);
}
Console.ReadLine();

解决方案

What's wrong with reading original MSDN documentation? http://msdn.microsoft.com/en-us/library/system.console.clear%28v=vs.110%29.aspx[^].

I think, writing such application is one of the worst ideas of the application, anyway.

—SA


I hopefully believe, you are writing this program for academic interest :-)

Your code has many issues...some are sorted below. Check if this helps. write some more code, experiment some more and read some more. Then if you still have issues, come back

int x;
 int total = 0;
 Console.SetCursorPosition(57, 2);
 Console.Write("Score:");
 Console.Write("\n\nQ:Pakistan National Gmae Is....?");
 Console.Write("\n\n1:Cricket.\n\n2:Hockey.\n\n3:Basketball.\n\n4:None.");
 Console.Write("\n\nChoice:");
 x = Convert.ToInt16(Console.ReadLine());
 if (x == 1)
 {
     Console.SetCursorPosition(65, 2);
     Console.WriteLine("{0}", total + 1);
 }
 else if (x != 1)
 {
     Console.WriteLine("{0}", total--);
 }
 Console.SetCursorPosition(1, 2);

 Console.Write("\n\nQ:Australia National Gmae Is....?");
 Console.Write("\n\n1:Cricket.\n\n2:Hockey.\n\n3:Basketball.\n\n4:None.");
 Console.Write("\n\nChoice:  ");
 Console.CursorLeft = Console.CursorLeft - 2;
 x = Convert.ToInt16(Console.ReadLine());
 if (x == 1)
 {
     Console.SetCursorPosition(65, 2);
     total = total + 2;
     Console.WriteLine("{0}", total);
 }
 else if (x != 1)
 {
     Console.SetCursorPosition(65, 2);
     Console.WriteLine("{0}", total--);
 }
 Console.ReadLine();



Cheers


这篇关于C#Console.Clear问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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