1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <iostream>// 输出流库 //#include<stdlib.h> //#define random(x) (rand()%x) using namespace std;//使用标准命名空间 //课程:5.2 流程结构 while循环猜数字 int main () { int i = 0; int j = 0; // 设置种子 //方法1: //j = random(100);// 生成实际的随机数 //方法2: srand((unsigned)time(NULL)); j = rand() % 100 + 1; cout << "请输入0~100数字: " << endl; while (i != j) { cin >> i; if (i == j) { cout << "当前数字输入正确: " << j << endl; //break; } else if (i < j) { cout << "当前输入的数字小于答案" << endl; } else { cout << "当前输入的数字大于答案" << endl; } } system("pause");// 控制台暂停,等待下一步操作 return 0;// 结束返回值:0 } |
05.2 C++while猜数字
未经允许不得转载:Ai分享 » 05.2 C++while猜数字