利用C++设计猜数字游戏

2024-11-27 16:26:43
推荐回答(3个)
回答(1):

#include //直接在库文件里找#include //包含了系统常用的函数#include #include void main(){ int n,i,number,gnumber,k,g,j; // n所猜数是几位数 xy 控制几到几 int x=1,y=1,a=0,b=0; int num[100],gnum[100];//正确数组 所猜数组 cout<<"Please input a number to determine the need to guess the number of digits :"<>n; system("cls");//清屏 for(i=0;i while(number!=gnumber)//循环 正确数 猜的数 不相等时循环 { cout<<"Please enter a guess the number of digits:"<>gnumber; g=gnumber; for(i=0;i

回答(2):

#include #include using namespace std;int main(){ srand((unsigned)time(NULL)); int num, temp, max=101, min=-1, n=0; cout << "输入一个数:" << endl; cin >> num; temp = rand() % max; n++; cout << "电脑——>" << temp << endl; int i = 0; while(i != 3) { cout << "选择结果( 1代表<, 2代表>, 3代表= ):" << endl; cin >> i; switch (i) { case 1: max = temp; cout << "数大了!" << endl; temp = rand() % max; while (temp <= min) { temp = rand() % max; } n++; cout << "电脑——>" << temp << endl; break; case 2: min = temp; cout << "数小了!" << endl; temp = rand() % max; while (temp <= min) { temp = rand() % max; } n++; cout << "电脑——>" << temp << endl; break; case 3: cout << "正确!" << endl; break; default: break; } } cout << "电脑总共猜了" << n << "次" << endl; return 0;} 试试

回答(3):

河工的