猜猜我是谁(猜数游戏)

游戏介绍

本游戏是最初版本。

主要是由for循环及if-else选择语句构成。

游戏玩法

第一个输入是游戏版本(1.单人        2.多人         3.退出)

第二个及下面的输入是输入猜的数,如机会用尽却没有猜对系统会公布正确答案。

这里我就不多说了直接上源代码:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <stdio.h>
using namespace std;
int main(void)
{
	int a,b,c,d,e,f,g;
	cout<<"      			【猜猜我是谁】目录系统"<<endl;
	cout<<"				1:单人模式"<<endl;
	cout<<"				2:多人模式"<<endl; 
	cout<<"				3:退出游戏"<<endl;
	cout<<endl;
	time_t t = time(0);
    char tmp[64];
    cout<<"		   打开时间:";
    strftime( tmp, sizeof(tmp), "  %Y/%m/%d %X ",localtime(&t) );
    puts( tmp );
    cout<<endl; 
	cout<<"请输入"; 
	cin>>a;
	cout<<endl;
	srand (time(NULL));
	d=10+rand()%(99-10+1); 
	if(a==3)
	{
		cout<<"已退出游戏"<<endl;
		return 0;
 	}
 	if(a==1)
 	{
 		cout<<"你有6次机会快来猜吧"<<endl;
 		for(f=1; f<=6;)
 		{
 			cout<<"请输入第"<<f<<"个数" ;
			cin>>e;
			if(e==d)
			{
				cout<<endl;
				cout<<"恭喜你猜对了!"<<endl;
				return 0;
			} 
			else if(e<d)
			{
				cout<<"小了"<<endl; 
				f=f+1;
			}
			else
			{
				cout<<"大了"<<endl; 
				f=f+1;
			} 
		}
		cout<<"机会用尽,正确答案为:"<<d;
		return 0;	 
	}
	if(a==2)
	{
		cout<<"请输入玩家数量";
		cin>>g;
		cout<<endl;
		for(f=1; f<=g; f++)
		{
			cout<<"请"<<f<<"号玩家猜数"<<endl;
			cout<<"请输入"; 
			cin>>e;
			if(e==d)
			{
				cout<<endl;
				cout<<"恭喜玩家"<<f<<"猜对了!"<<endl;
				return 0;
			} 
			else if(e<d)
			{
				cout<<"小了"<<endl;
				cout<<endl; 
			}
			else
			{
				cout<<"大了"<<endl;
				cout<<endl; 
			} 
		}
		cout<<endl;
		cout<<"正确答案是"<<d; 
	} 	
	return 0;
}

/*
=================================================== 
曹炜哲同学制作 
(roboone.scratch3.fun)
---------------------------------------------------
鸣谢:
@adengou
已及roboone编程教师-黄老师
===================================================
*/ 

制作者学习编程的网站

制作者使用的网站

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值