作业帮 > 综合 > 作业

帮忙解析一个语句#include "stdafx.h"#include "stdio.h"#include "time.

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/01 18:17:20
帮忙解析一个语句
#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() %
srand(unsigned(time(NULL))); //设定种子
intComputerChoice = 1 + rand() % 3; //产生随机数
随机数对3取余结果只能是0,1,2 ,加 1就变成1,2,3了.产生1-3的随机数
再问: 我的q:245186206,希望能加你交流编程
再答: 已加,欢迎交流C语言相关知识