- UID
- 315497
- 在线时间
- 0 小时
- 最后登录
- 1970-1-1
- 注册时间
- 2013-1-3
- 宅魂
- 1270 点
- 贡献
- 381 点
- 宅币
- 4343 枚
- 灵石
- 0 块
- 元气(技能点)
- 8 点
- 活跃
- 25 ℃
- 听众
- 8
- 收听
- 3
签到天数: 5 天 连续签到: 1 天 [LV.2]偶尔看看I
中二病
Dark Frame Master!
- 积分
- 9747
|
本帖最后由 绯色の胖子 于 2015-6-12 18:12 编辑
题目:从键盘上输入两个整数,由用户回答它们的和,差,积,商和取余运算结果,并统计出正确答案的个数。
代码:
[mw_shl_code=applescript,true]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("if you want to exit this program,press enter directly.");
try { ToDo(); }
catch (Exception ex) { Console.WriteLine(ex); }
}
public static void ToDo()
{
int a = 0;
int b = 0;
int c = 0;
int result1=0;
int result2=0;
int i=0;
do
{
Console.WriteLine("input first num");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("input second num:");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("input operator:1=plus,2=minuse,3=multiply,4=devide");
c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("input result:");
result1 = Convert.ToInt32(Console.ReadLine());
switch (c)
{
case 1:
result2 = a + b;
break;
case 2:
result2 = a - b;
break;
case 3:
result2 = a * b;
break;
case 4:
result2 = a / b;
break;
default :
break;
}
if (result1 == result2)
{
i++;
}
Console.WriteLine("correct time is {0}", i);
} while (i>0);
}
}
}
[/mw_shl_code]
纯自学……没老师……
求建议,求优化! |
评分
-
查看全部评分
|