学校的要求练习
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <time.h>
int main()
{
int computerNumber,userNumber;
char ch='y';
bool IsContine=true;
while(IsContine)
{
srand(time(NULL));
computerNumber=(int)(rand()%3);
printf("请输入用户你的选择:0-剪刀 1-石头 2-布\n");
scanf("%d",&computerNumber);
switch(computerNumber)
{
case 0:
if(userNumber == 0)
{
printf("你:剪刀 计算机:剪刀 平局~\n");
}
else if(userNumber == 1)
{
printf("你:石头 计算机:剪刀 你胜利了!\n");
}
else if(userNumber == 2)
{
printf("你:布 计算机:剪刀 很遗憾你输了~\n");
}
break;
case 1:
if(userNumber == 0)
{
printf("你:剪刀 计算机:石头 很遗憾你输了~\n");
}
else if(userNumber == 1)
{
printf("你:石头 计算机:石头 平局~\n");
}
else if(userNumber == 2)
{
printf("你:布 计算机:石头 你胜利了!\n");
}
break;
case 2:
if(userNumber == 0)
{
printf("你:剪刀 计算机:布 你胜利了!\n");
}
else if(userNUmber == 1)
{
printf("你:石头 计算机:布 很遗憾你输了~\n");
}
else if(userNumber == 2)
{
printf("你:布 计算机:布 平局~\n");
}
break
}
printf("是否继续游戏(y/n?)");
getcher();
scanf("%c",&ch);
if(cj==='y'||ch=='y')
IsContine=true;
else IsContine=false;
}
return 0;
}
3 19 C:\Users\HUAWEI\Desktop\8.c [Error] cstdlib: No such file or directory
compilation terminated.
能跑出来
代码修复后如下
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <time.h>
int main()
{
int computerNumber, userNumber;
char ch = 'y';
bool IsContine = true;
while (IsContine)
{
srand(time(NULL));
computerNumber = (int)(rand() % 3);
printf("请输入用户你的选择:0-剪刀 1-石头 2-布\n");
scanf("%d", &userNumber);
switch (computerNumber)
{
case 0:
if (userNumber == 0)
{
printf("你:剪刀 计算机:剪刀 平局~\n");
}
else if (userNumber == 1)
{
printf("你:石头 计算机:剪刀 你胜利了!\n");
}
else if (userNumber == 2)
{
printf("你:布 计算机:剪刀 很遗憾你输了~\n");
}
break;
case 1:
if (userNumber == 0)
{
printf("你:剪刀 计算机:石头 很遗憾你输了~\n");
}
else if (userNumber == 1)
{
printf("你:石头 计算机:石头 平局~\n");
}
else if (userNumber == 2)
{
printf("你:布 计算机:石头 你胜利了!\n");
}
break;
case 2:
if (userNumber == 0)
{
printf("你:剪刀 计算机:布 你胜利了!\n");
}
else if (userNumber == 1)
{
printf("你:石头 计算机:布 很遗憾你输了~\n");
}
else if (userNumber == 2)
{
printf("你:布 计算机:布 平局~\n");
}
break;
}
printf("是否继续游戏(y/n?)");
getchar();
scanf("%c", &ch);
if (ch == 'y' || ch == 'y')
IsContine = true;
else
IsContine = false;
}
printf("20213002788张欣苗\n");
return 0;
}