垃圾分类2.0

这篇文章介绍了一个使用C++编写的垃圾分类小游戏,通过随机选择题目测试用户对可回收垃圾、干垃圾、湿垃圾和有害垃圾的识别能力,并计算正确率。
摘要由CSDN通过智能技术生成

经过小编的学习与优化,垃圾分类2.0它来了!

#include <bits/stdc++.h>
#include <stdlib.h>
#include <windous.h>
using namespace std;

int main()
{
	int a,b,c,d,e,g;
	double num,t=0,f=0;
	string ke [10] = {"玻璃","书本纸张","报纸","包装纸","办公用纸","广告纸片","纸盒","易拉罐","塑料袋","泡沫塑料"};	
	string gan[10] = {"尿不湿","猫砂","狗尿垫","污损纸张","烟蒂","干燥剂","毛发","灰土","橡皮泥","太空沙"};
	string shi[10] = {"菜根","动物蹄","菜叶","瓜皮","果屑","蛋壳","鱼鳞","植物枝干","树叶","杂草"};
	string hai[10] = {"废水银温度计","过期药品","废油漆","废农药","杀虫剂","废医用棉签","荧光棒","纽扣电池","废节能灯","废荧光灯管"};
	cout <<"         ******************************************************************************************************" <<endl;
	cout <<"         *************************************垃圾分类小游戏***************************************************" <<endl;
	cout <<"         **************************************作者:小编****************************************************" <<endl; 
	cout <<"         ******************************************************************************************************" <<endl;
	cout <<"         ****************************************6.开始********************************************************" <<endl;
	cout <<"         ****************************************7.退出********************************************************" <<endl;
	cout <<"         ******************************************************************************************************" <<endl; 
	cout <<"         ***************************************游戏规则*******************************************************" <<endl; 
	cout <<"         *****1.垃圾分为可回收垃圾(1),干垃圾(2),湿垃圾(3),有害垃圾(4)(输入对应数字,然后按回车)*****" <<endl;
	cout <<"         *****2.游戏会判断对错,你只需要做题就行***************************************************************" <<endl; 
	cout <<"         *****3.你可以随时按7退出(输入7,按回车)*************************************************************" <<endl;
	cout <<"         *****4.游戏一共10道题*********************************************************************************" <<endl;
	cout <<"         ******************************************************************************************************" <<endl;
	cin >> a;
	if(a==6)
	{	
		system("cls");
		for(int j=0;j<10;j++)
		{
			srand(time(0));
			b = rand() % 10 + 1;
			d = rand() % 4 + 1;
			if (d==1)
			{
				cout<<ke[b];
			}else if (d==2)
			{
				cout<<gan[b];
			}else if (d==3)
			{
				cout<<shi[b];
			}else
			{
				cout<<hai[b];
			}
			cin>>e;
			if(e==7)
			{
				return 0; 
			}else if(e==d)
			{
				cout<<"恭喜你,答对了" <<endl;
                sleep(1000);
				t++;
				system("cls");
			}else if (e!=d)
			{
				cout<<"答错了,它是";
				if (d==1)
				{
					cout<<"可回收垃圾"<<endl;
                    sleep(1000);
					f++;
					system("cls");
				}else if (d==2)
				{
					cout<<"干垃圾"<<endl;
                    sleep(1000);
					f++;
					system("cls");
				}else if (d==3)
				{
					cout<<"湿垃圾"<<endl;
                    sleep(1000);
					f++;
					system("cls");
				}else
				{
					cout<<"有害垃圾"<<endl;
                    sleep(1000);	
					f++;
					system("cls");
				} 
			}
		}
		num= double (t/(f+t));
		cout<<"你答对了"<<t<<"道题," <<"答错了"<<f<<"道题,"<<"正确率是" <<num*100<<"%"; 
		return 0;
	}else if(a==7)
	{
		return 0;
	}
}

 随机数是真没办法了,有大佬知道怎么改的话请评论让小编学习一下,感谢♪(・ω・)ノ。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值