有人可以告诉我的代码有什么问题吗?
玩家将掷两个骰子。在第一次投掷如果两者的总和 骰子等于7或11,玩家获胜。如果总和等于2,3或12 球员输了。任何其他总和,游戏将继续,和总和 将成为球员“积分”。玩家将再次掷出两个骰子 并再次实现球员“积分”。如果玩家达到了这个目标, 玩家获胜。如果玩家在达到“积分”之前掷出7 球员输了。平安!
#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;
}
答案 0 :(得分:2)
}while ( score_n == point || score_n == 7 );
只有当得分==指数或7,你想要
时,循环才会继续 }while ( score_n != point && score_n != 7 );