标题:小学算术题测试 好多错 指点下!!!
只看楼主
wanxingdai
Rank: 1
等 级:新手上路
帖 子:31
专家分:6
注 册:2010-9-21
结帖率:55.56%
已结贴  问题点数:15 回复次数:1 
小学算术题测试 好多错 指点下!!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 小学算数题
{
    class Program
    {
        static void Main(string[] args)
        {
         
            write("你想做什么范围的呢?");
            int max = Convert.ToInt32(Console.ReadLine());
            while (true)
            {
                char ops;
                int op;
                Random r = new Random();
                Random c= new Random();
                Random a=(int) ((r.Next()/int.MaxValue*1.0)*max);
                Random b = (int)((r.Next() / int.MaxValue * 1.0) * max);
                Random op = (int)((c.Next() / int.MaxValue * 1.0) * 4);
                chuti(a,ops,b);
                int sum = input();
                if (torf(a+b, sum)) Console.Write("正确");
                else Console.Write("错误");
            }

        }
        static void chuti(int a,char ops,int b,int op)
        {
            switch (op)
            {
                case 0: ops = '+'; Console.Write("a"); Console.Write("+"); Console.Write("b"); Console.Write("="); break;
                case 1: ops = '-';
                    //if(a>=b)
                    Console.Write("a"); Console.Write("-"); Console.Write("b"); Console.Write("="); break;
                //else write(a); write("+"); write(b); break;
                case 2: ops = '*'; Console.Write("a"); Console.Write("*"); Console.Write("b"); Console.Write("="); break;
                case 3: ops = '/'; Console.Write("a"); Console.Write("/"); Console.Write("b"); Console.Write("="); break;
            }
           
        }
        static int input()
        {
            return  Convert.ToInt32(Console.ReadLine());
        }
        static bool torf(int result,int input)
        {
            return result == input ? true : false;
        }
    }
}
搜索更多相关主题的帖子: 算术题 
2011-03-30 21:47
zhp223
Rank: 5Rank: 5
等 级:职业侠客
帖 子:99
专家分:362
注 册:2010-3-21
得分:15 
Random a=(int) ((r.Next()/int.MaxValue*1.0)*max);
Random b = (int)((r.Next() / int.MaxValue * 1.0) * max);
Random op = (int)((c.Next() / int.MaxValue * 1.0) * 4);

改成:
int a=(int) ((r.Next()/int.MaxValue*1.0)*max);
int b = (int)((r.Next() / int.MaxValue * 1.0) * max);
int op = (int)((c.Next() / int.MaxValue * 1.0) * 4);

日有所思,夜有所梦
2011-03-31 12:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-335239-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.066382 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved