帮忙解析一个语句#include "stdafx.h"#include "stdio.h"#include "time.h"#include "stdlib.h"int main() {intintComputerChoice,intUserChoice;srand(unsigned(time(NULL)));intComputerChoice = 1 + rand() % 3;printf("Enteryour choice (1—Rock; 2—Pap
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/06 08:49:36
帮忙解析一个语句#include "stdafx.h"#include "stdio.h"#include "time.h"#include "stdlib.h"int main() {intintComputerChoice,intUserChoice;srand(unsigned(time(NULL)));intComputerChoice = 1 + rand() % 3;printf("Enteryour choice (1—Rock; 2—Pap
帮忙解析一个语句
#include "stdafx.h"
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
int main()
{
intintComputerChoice,intUserChoice;
srand(unsigned(time(NULL)));
intComputerChoice = 1 + rand() % 3;
printf("Enteryour choice (1—Rock; 2—Paper; 3—Scissors):");
scanf("%d",&intUserChoice);
printf("Mychoice:");
//★
switch (intComputerChoice)
{ case 1:
printf("Rock;\n"); break;
case 2:
printf("Paper;\n"); break;
case 3:
printf("Scissors;\n"); break;
}
printf("Yourchoice:");
//★
switch (intUserChoice)
{ case 1:
printf("Rock;\n"); break;
case 2:
printf("Paper;\n"); break;
case 3:
printf("Scissors;\n"); break;
}
//★
switch (intComputerChoice- intUserChoice)
{ case 0:
printf("Wetied!"); break;
case 1:
case -2:
printf("Youlose the game.I win.\n"); break;
case -1:
case 2:
printf("Youwin.I lose the game.\n"); break;
default:
printf("Yourchoice is not correct.\n");
}
return 0;
}
其中的那个intComputerChoice = 1 + rand() %
帮忙解析一个语句#include "stdafx.h"#include "stdio.h"#include "time.h"#include "stdlib.h"int main() {intintComputerChoice,intUserChoice;srand(unsigned(time(NULL)));intComputerChoice = 1 + rand() % 3;printf("Enteryour choice (1—Rock; 2—Pap
srand(unsigned(time(NULL))); //设定种子
intComputerChoice = 1 + rand() % 3; //产生随机数
随机数对3取余结果只能是0,1,2 ,加 1就变成1,2,3了.产生1-3的随机数