C 一个游戏的机会,一个模拟器为一个非常简单的骰子游戏
谁能告诉我我的代码有什么问题吗 玩家将掷两个骰子。在第一次投掷中,如果两个的总和 骰子等于7或11,玩家获胜。如果总和等于2、3或12 玩家输了。任何其他金额,游戏将继续,和金额 将成为玩家的“积分”。玩家将再次掷两个骰子 再次达到玩家的“积分”。如果玩家做到了这一点, 玩家赢了。如果玩家在获得“点数”之前掷7 球员输了 和平C 一个游戏的机会,一个模拟器为一个非常简单的骰子游戏,c,C,谁能告诉我我的代码有什么问题吗 玩家将掷两个骰子。在第一次投掷中,如果两个的总和 骰子等于7或11,玩家获胜。如果总和等于2、3或12 玩家输了。任何其他金额,游戏将继续,和金额 将成为玩家的“积分”。玩家将再次掷两个骰子 再次达到玩家的“积分”。如果玩家做到了这一点, 玩家赢了。如果玩家在获得“点数”之前掷7 球员输了 和平 #include <stdio.h> #include <stdlib.h> #include <time.h> int rand_
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rand_num()
{
return ( 1 + (rand()%6) );
}
int main( void )
{
int D1, D2, score, point;
int D3, D4, score_n = 0;
srand ( time( NULL ) );
D1 = rand_num();
D2 = rand_num();
score = D1 + D2;
printf( "You rolled %d + %d = %d", D1, D2, score );
if ( score == 7 || score == 11 )
printf( "\n\nYou win!");
else if ( score == 2 || score == 3 || score == 12 )
printf( "\n\nYou lose!");
else
{
point = score;
printf( "\n\nYou must get %d to win", point);
do
{
D3 = rand_num();
D4 = rand_num();
score_n = D3 + D4;
printf( "\n\nYou rolled %d + %d = %d", D3, D4, score_n );
if ( score_n == 7 )
printf( "\n\nYou lose!" );
if ( score_n == point )
printf( "\n\nYou win!" );
}while ( score_n == point || score_n == 7 );
}
return 0;
}
#包括
#包括
#包括
int rand_num()
{
返回值(1+(rand()%6));
}
内部主(空)
{
积分D1,D2,分数,分;
int D3,D4,得分=0;
srand(时间(空));
D1=rand_num();
D2=rand_num();
得分=D1+D2;
printf(“您滚动了%d+%d=%d”,D1,D2,分数);
如果(分数=7 | |分数=11)
printf(“\n\n您赢了!”);
否则如果(分数=2 | |分数=3 | |分数=12)
printf(“\n\n您输了!”);
其他的
{
分数=分数;
printf(“\n\n您必须获得%d才能获胜”,点数);
做
{
D3=随机数();
D4=随机数();
得分=D3+D4;
printf(“\n\n您滚动了%d+%d=%d”,D3,D4,分数);
如果(分数=7)
printf(“\n\n您输了!”);
如果(分数=分)
printf(“\n\n您赢了!”);
}而(得分=7分);
}
返回0;
}
只有当分数==点或7,循环才会继续
}while ( score_n != point && score_n != 7 );
现在怎么了?编译时错误?运行时错误?输出不正确?
}while ( score_n != point && score_n != 7 );