c++编程问题,急求答案啊!!!
The first die comes up 3
The second die comes up 5
Your total roll is 8 展开
#include<iostream>
#include <time.h>
using namespace std;
#define DiceMax 6
#define DiceTime 2
unsigned FirstDice,SecondDice,Total;
double Average;
void InitDice(){
srand(time(NULL));
cout<<"=============Start Dicing:============="<<endl;
}
unsigned Dice (){
return rand()%DiceMax + 1;
}
double CacularAver(unsigned DicingTime ){
return (Total = ((FirstDice = Dice() ) + (SecondDice = Dice()))) / DicingTime ;
}
void Display(unsigned FirstDice,unsigned SecondDice,unsigned Total,double Average){
cout<<"The first die comes up "<<FirstDice<<endl;
cout<<"The second die comes up"<<SecondDice<<endl;
cout<<"Your total roll is "<<Total<<endl;
cout<<"Your Average roll is "<<Average<<endl;
}
int main(){
char Continute = 'y';
InitDice();
do{
Display(FirstDice,SecondDice,Total,Average = CacularAver( DiceTime ));
cout<<"Continute?(y/n):";
cin>>Continute;
}while(Continute == 'y' || Continute == 'Y');
cout<<"===========Dicing End============="<<endl;
return 0;
}
#include <stdio.h>
#include<conio.h>
#include <time.h>
int main(void)
{
int i=2 ,h=5;
int r,s,j,d,y;
int sz[10]={1,2,3,4,5,6};
srand(time(NULL));
r=rand()%(10-i);
printf("The first die comes up %d\n",sz[r]);
y=sz[r];
for( j=r;j<10;j++)
sz[j]=sz[j+1];
s=rand()%(10-h);
printf(" The second die comes up %d\n",sz[s]);
printf("Your total roll is %d\n",y+sz[s]);
for(d=s;d<10;d++)
sz[d]=sz[d+1];
getch();
return 0;
}
不会就要问啊