- //
- // Copyright (c) 2014软件技术1班
- // All rights reserved.
- // 作 者:A30 黄勇华
- // 完成日期:2014年 11 月 17 日
- // 版 本 号:v1.0
- //
- // 问题描述:创建一个程序制作一个简单的猜数游戏
- // 输入描述:输入猜想的数字,由计算机判断正误并给出提示
- // 程序输出:给出游戏提示与结果
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
-
- namespace 猜数
- {
- class Program
- {
- static void Main(string[] args)
- {
- string i = null;
- Random rnd = new Random();
- int rndInt = rnd.Next(1, 100);
- int input = 0;
- do
- {
- Console.Write("输入你猜的数值:");
- i = Console.ReadLine();
- if (!int.TryParse(i, out input))
- {
- continue;
- }
- if (input > rndInt)
- {
- Console.Write("猜大了\n\n");
- }
- else if (input < rndInt)
- {
- Console.Write("猜小了\n\n");
- }
- } while (input != rndInt);
- Console.Write("恭喜你,猜对了!\n\n");
-
-
- Console.Read();
- }
- }
- 输出:
-
- 总结:
- 1.在这次作业中学会了随机变量的布置
- 2.加强了分支话语句的应用
- 3.更能体会到循环所需要的条件与环境
猜数游戏
最新推荐文章于 2021-12-12 21:05:24 发布