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

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

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("四则运算答题");
        
                    int a, b, d, c1,c2,t=0;
                    Random rnd = new Random();
                    do
                    {
                       
                        a = rnd.Next(1, 10);
                        b = rnd.Next(1, 10);
                        d = rnd.Next(1, 4);
                        t++;
                        Console.WriteLine("第{0}题:",t);

                        if (d == 1)
                        {
                            c1 = a * b;
                            Console.WriteLine("{0}x{1}=", a, b );
                            Console.WriteLine("请计算答案:");
                            c2 = int.Parse( Console.ReadLine());
                            if (c2 == c1)
                                Console.WriteLine("计算正确,按Enter进行下一题");
                            else
                                Console.WriteLine("计算错误,正确结果为:{0}。按Enter进行下一题", c1);
                        }
                        else if (d == 2)
                            if (a >= b)
                            {
                                c1 = a / b;
                                Console.WriteLine("{0}/{1}=", a, b);
                                Console.WriteLine("请计算答案:");
                                c2 = int.Parse(Console.ReadLine());
                                if (c2 == c1)
                                    Console.WriteLine("计算正确,按Enter进行下一题");
                                else
                                    Console.WriteLine("计算错误,正确结果为:{0}。按Enter进行下一题", c1);
                            }
                            else
                            {
                                c1 = b / a;
                                Console.WriteLine("{0}/{1}=", a, b);
                                Console.WriteLine("请计算答案:");
                                c2 = int.Parse(Console.ReadLine());
                                if (c2 == c1)
                                    Console.WriteLine("计算正确,按Enter进行下一题");
                                else
                                    Console.WriteLine("计算错误,正确结果为:{0}。按Enter进行下一题", c1);
                            }


                        else if (d == 3)
                        {
                            c1 = a + b;
                            Console.WriteLine("{0}+{1}=", a, b);
                            Console.WriteLine("请计算答案:");
                            c2 = int.Parse(Console.ReadLine());
                            if (c2 == c1)
                                Console.WriteLine("计算正确,按Enter进行下一题");
                            else
                                Console.WriteLine("计算错误,正确结果为:{0}。按Enter进行下一题", c1);
                          
                        }
                        else if (d == 4)
                        {
                            c1 = a - b;
                            Console.WriteLine("{0}-{1}=", a, b);
                            Console.WriteLine("请计算答案:");
                            c2 = int.Parse(Console.ReadLine());
                            if (c2 == c1)
                                Console.WriteLine("计算正确,按Enter进行下一题");
                            else
                                Console.WriteLine("计算错误,正确结果为:{0}。按Enter进行下一题", c1);

                        }

                    }
                    while (Console.ReadLine()!="10000000000000");
     
                Console.Read();
            }
        }
    }

    不会用窗口做,只能用控制台做了

  • 相关阅读:
    Spring Boot 创建一个可以执行的 Jar
    Spring Boot 第一个示例启动运行
    Spring Boot 第一个示例 “main” 方法
    Spring Boot 第一个示例 @EnableAutoConfiguration 注解
    Spring Boot 第一个示例的 @RestController 和 @RequestMapping 注解
    Spring Boot 2.4 第一个示例程序书写代码
    Spring Boot 2.4 第一个示例程序添加 Classpath 依赖
    Spring Boot 2.4 示例创建 POM 文件
    Spring Boot 2.4 部署你的第一个 Spring Boot 应用需要的环境
    Mysql 的concat、concat_ws()以及group_concat()的用法与区别
  • 原文地址:https://www.cnblogs.com/liti/p/4869351.html
Copyright © 2011-2022 走看看