C++扔色子的代码怎么写?

来源:百度知道 编辑:UC知道 时间:2024/06/15 12:20:37
In each turn a number between 1 and 6 is generated (which represents the player throwing a six side dice).

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"输入随机因子:"<<endl;
int n;
cin>>n;
srand(n);
char c;
do{
c='n';
cout<<"若果头色子请输入y"<<endl;
cin>>c;
if(c=='y')
cout<<rand()%6+1<<endl;
}while(c=='y')
return 0;
}
调试过了 可以的

LS的:
rand()%5+1
改为:
rand()%6+1