C++

猜数字

#include<iostream>usingnamespacestd;//time系统时间头文件包含#include<ctime>intmain(){srand((unsignedint)time(NULL));//添加随机数种子利用系统当前时间,防止生成每一次都一样intnum=rand()%100+1;//rand()%100+1生成0+1~100+1的随机数intval=0;cout<<"请输入数字:";while(1){cin>>val;if(val==num){cout<<"您猜对了";break;//推出当前循环}elseif(val>num){cout<<"您猜的数大了,"<<"请重新输入数字:";}else{cout<<"您猜的数小了,"<<"请重新输入数字:";}}system("pause");return0;}

C++

Swith语句

#include<iostream>usingnamespacestd;intmain(){intday;cout<<"请输入0~6:";cin>>day;switch(day){case0:cout<<"sunday"<<endl;break;case1:cout<<"monday"<<endl;break;case2:cout<<"tuesday"<<endl;break;case3:cout<<"wednesday"<<endl;break;case4:cout<<"thursday"<<endl;break;case5:cout<<"firday"<<endl;break;case6:cout<<"saturday"<<endl;break;default:cout<<"输入有误"<<endl;break;}system("pause");return0;}

Title - Artist
0:00