只是一个简单的问题。 我对C++很陌生。在这里我创建了一个随机数发生器,它应该从1-3开始得到一个随机数,然后每个数字对应岩石纸或剪刀。Rock Paper Scissors的随机数
问题是,它每次都会选择剪刀(3)!我做错了什么?
#include<stdio.h>
#include<stdlib.h>
int i, a, b;
int playerschoice, compchoice;
main()
{
compchoice=rand() %3+1;
printf("compchoice=%d",compchoice);
if (compchoice == 1)
{
printf("\nThe computer is going with: Rock...\n");
b = 0;
}
else if (compchoice == 2)
{
printf("\nThe computer is going with: Paper...\n");
b = 1;
}
else if (compchoice == 3)
{
printf("\nThe computer is going with: Scissors...\n");
b = 2;
}
system("pause");
return 0;
}
这个问题被标记为C++,但它看起来非常像C. – JustSid
如果你满意下面的答案,你能接受它吗? – Akshay