猜数游戏
来源:互联网 发布:克苏鲁神话知乎 编辑:程序博客网 时间:2024/06/08 06:33
//软件技术一班//作者:A29邢晓康//完成日期:2014/11/16//问题描述:随机产生一个1~100之间的数,要求将输入的数与随机产生的数进行比较。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 猜数{ class Program { static void Main(string[] args) { bool w = true; while (w) { int rndNum; Random rnd = new Random(); rndNum = rnd.Next(0, 100); int num1 = rnd.Next(0, 100); bool a = true; int i = 0; while (a) { Console.WriteLine("请输入您猜的数字,该数字在1~100之间"); int num2 = int.Parse(Console.ReadLine()); if (num2 >= 0 & num2 <= 100) { i = i + 1; if (num2 > num1) { Console.WriteLine("大了,"); a = true; Console.WriteLine("这是第{0}次猜测,请再输入一次 ", i); } else { if (num2 < num1) { Console.WriteLine("小了,"); a = true; Console.WriteLine("这是第{0}次猜测,请再输入一次 \n", i); } else { Console.WriteLine("这是第{0}次猜测,请再输入一次 \n", i); Console.WriteLine("被你发现了,没错!这个数就是{0}", num1); Console.WriteLine("是否继续猜数?1是,2否"); int b = int.Parse(Console.ReadLine()); if (b == 1) { a = false; w = true; } else { a = false; w = false; } } } } else { Console.WriteLine("sorry,只能输入1~100之间的数"); w = true; } } } } }}
总结:通过此次作业我略微了解到了产生随机数的几个语句,与循环语句的实际应用。
0 0
- 猜数游戏程序
- 人机猜数游戏
- 1995猜数游戏
- Java猜数游戏
- 猜数游戏
- 猜数游戏
- 文曲星猜数游戏
- java猜数游戏
- 猜数游戏
- 猜数游戏
- 猜数游戏
- 猜数游戏
- 猜数游戏
- 猜数游戏
- 猜数游戏
- java 猜数游戏
- 人机猜数游戏
- 猜数游戏
- TNS-01106: Message 1106 not found; No message file for product=network, facility=TNS
- 根据Windows Access Control Model自己画的图
- Achartengine 条形图,折线图,饼状图
- UML图——类图
- 第十二周项目三——用递归方法求解(5)
- 猜数游戏
- python 安装sklearn
- 第十二周项目三(5) 求n的二进制形式
- 第十二周 项目4:任务一 搭框架
- 【Python笔记】如何理解python中的generator functions和yield表达式
- Ascil与unicode区别
- ORA-01507: database not mounted
- 人工智能塑造科幻大片式的未来
- iOS使用滤镜