跳到正文

休闲·娱乐

<小牛蛙游戏集>猜数字游戏

Void_Trailwalker约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年1月28日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	srand((unsigned int)time(NULL));
	cout << "猜数字游戏开始!\n";
	T:
		cout << "输入数据范围:";
		int m;
		cin >> m;
		cout << "\n";
		m += 1;
		int n = rand()%m;
		int num;
		cout << "输入次数:";
		cin >> num;
		cout << "------------------------------------------------------------------------------------------------------------------------";
		int t;
		for(int i=1;i<=num;i++){
			cout << "输入你的答案:";
			cin >> t;
			if(t==n){
				cout << "你赢了!\n是(1)否(0)再来一局?";
				cin >> t;
				if(t){
					cout << "------------------------------------------------------------------------------------------------------------------------";
					goto T;
				}else{
					return 0;
				}
			}
			else if(t>n){
				cout << "大了\n";
			}else{
				cout << "小了\n";
			}
			cout << "------------------------------------------------------------------------------------------------------------------------";
		}
	cout << "哈哈哈!正确答案是" << n;
	cout << "\n是(1)否(0)再来一局?";
	cin >> t;
	if(t){
		goto T;
	}else{
		return 0;
	}
}
原文