经过小编的学习与优化,垃圾分类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;
}
}
随机数是真没办法了,有大佬知道怎么改的话请评论让小编学习一下,感谢♪(・ω・)ノ。