垃圾分类游戏2.1

昨天测试了一下,发现用for循环有bug,今天就用while做了一个。

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

int main()
{
	int a,b,c,d,e,g,h=0;
	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");
    	while(h<10)
    	{
    		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");
				} 
			}
			h++;
		}
		num= double (t/(f+t));
		cout<<"你答对了"<<t<<"道题," <<"答错了"<<f<<"道题,"<<"正确率是" <<num*100<<"%"; 
		return 0;
	}else if(a==7)
	{
		return 0;
	}
}

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值