猜数游戏

  1. //  
  2. // Copyright (c) 2014软件技术1班  
  3. // All rights reserved.   
  4. // 作    者:A30  黄勇华  
  5. // 完成日期:2014年 11 月 17 日   
  6. // 版 本 号:v1.0   
  7. //   
  8. // 问题描述:创建一个程序制作一个简单的猜数游戏  
  9. // 输入描述:输入猜想的数字,由计算机判断正误并给出提示   
  10. // 程序输出:给出游戏提示与结果
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;


  16. namespace 猜数
  17. {
  18.     class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             string i = null;
  23.  
  24.   Random rnd = new Random();
  25.   int rndInt = rnd.Next(1, 100);
  26.   int input = 0;
  27.   do
  28.   {
  29.   Console.Write("输入你猜的数值:");
  30.   i = Console.ReadLine();
  31.   if (!int.TryParse(i, out input))
  32.   {
  33.   continue;
  34.   }
  35.   if (input > rndInt)
  36.   {
  37.   Console.Write("猜大了\n\n");
  38.   }
  39.   else if (input < rndInt)
  40.   {
  41.   Console.Write("猜小了\n\n");
  42.   }
  43.   } while (input != rndInt);
  44.   Console.Write("恭喜你,猜对了!\n\n");


  45.   Console.Read();
  46.   }
  47.         }
  48. 输出:

  49. 总结:
  50. 1.在这次作业中学会了随机变量的布置
  51. 2.加强了分支话语句的应用
  52. 3.更能体会到循环所需要的条件与环境
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值