zoukankan      html  css  js  c++  java
  • 四则运算

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace jiajianchengchu
    {
    class Program
    {
    static void Main(string[] args)
    {

    int z=0;
    int x = 1;
    int o = 0;
    Random r = new Random();



    while(z<1)
    {
    int a = r.Next(0, 11);
    int b = r.Next(0, 11);
    int c = r.Next(0, a);
    int d = r.Next(1,11);
    Console.WriteLine("请出入1为加,2为减,,3为乘,4为除");
    int y = int.Parse(Console.ReadLine());
    switch (y)
    {
    case 1:
    Console.WriteLine("第{0}题:{1} + {2} = ? ", x, a, b);
    int result = Convert.ToInt32(Console.ReadLine());
    if (result == a + b)
    {
    o++;

    ;

    }
    x++;
    break;
    case 2:
    Console.WriteLine("第{0}题:{1} - {2} = ? ", x, a, c);
    int result2 = Convert.ToInt32(Console.ReadLine());
    if (result2 == a-c)
    {
    o++;

    }
    x++;

    break;
    case 3:
    Console.WriteLine("第{0}题:{1} * {2} = ? ", x, a, b);

    int result3 = Convert.ToInt32(Console.ReadLine());

    if (result3 == a*b)
    {
    o++;

    }
    x++;
    break;
    case 4:
    Console.WriteLine("第{0}题:{1} / {2} = ? ", x, a, d);

    int result4 = Convert.ToInt32(Console.ReadLine());
    ;
    if (result4 == a/d)
    {
    o++;

    }
    x++;
    break;


    }
    Console.WriteLine("输入0继续答题,输入1结束答题");
    int z1 = int.Parse(Console.ReadLine());
    z = z + z1;

    }

    Console.WriteLine("你一共答了{0}题,你答对了{1}题",x-1,o );
    Console.ReadLine();


    }
    }
    }

    需求分析  :创建一个能随机产生10以内数字的加减乘除运算能计算正确和错误题数。

    具体思路  :首先要选择加减乘除 ,用 switch case语句  然后又加了一个while语句循环 具体框架就是这样

    psp耗时   :我预计七个小时左右实现   我从网上参考别人代码大概半个小时 具体动手做一个半小时 修改代码十分钟

    个人总结:实践才是检验能力唯一标准,在做的遇到了很多麻烦 比如用了case语句 只执行一次就返回怎么办,然后想加一个循环。如何选择下一题加一个判断该在哪加;

    随机数应该写在那个位置  循环里还是循环外;感觉写一个代码真的很不容易  ;革命尚未成功同志们 ,仍需努力......

    至于git程序全英看不还没有学会用

  • 相关阅读:
    反射
    IO流
    集合(下)
    集合(上)
    泛型
    异常
    常用类
    内部类
    将博客搬至CSDN
    DBMS_ERRLOG记录DML错误日志(二)
  • 原文地址:https://www.cnblogs.com/fei2/p/4852090.html
Copyright © 2011-2022 走看看