我正在用 C 编写一个程序,它将掷两个骰子并输出总和。游戏很简单,现在我正在合并一个函数和循环,以便使用将进行多次尝试。问题是第一次尝试后分数永远不会改变。所以我知道该功能正在工作,但不知何故循环正在抛出一些东西。这是我的代码:
#include<stdio.h>
//Function prototype
int RollScore(int , int);
main()
{
int LoopCount;
LoopCount = 0;
for(LoopCount = 0; LoopCount < 11; LoopCount ++)
{
//Declare Variables
int DieOne,DieTwo,DiceScore;
// One and Two will be hidden only Score will be output
DieOne = 0;
DieTwo = 0;
DiceScore = 0;
printf("\n\n\tTo win you need a score of 7 or 11.");
printf("\n\n\tPress a key to Roll the Dice!");
//Trigger Random number generator and remove previous text
getch();
system("cls");
DiceScore = RollScore(DieOne , DieTwo);
//Create Condition to either show user a win/lose output
if (DiceScore == 7 || DiceScore == 11)
{
printf("\n\n\n\t\tYou Rolled a score of %d" , DiceScore);
printf("\n\n\n\t\tCongratulation! You win!");
LoopCount = 11;
}//end if
else
{
printf("\n\n\n\t\tYou Rolled a score of %d" , DiceScore);
printf("\n\n\n\t\tSorry you have lost! Thanks for playing!");
printf("\n\n\t %d Attempt!" , LoopCount);
}//end else
//Prevent the IDE from closing program upon termination
getch();
system("cls");
}//End For
}
//Function definition
int RollScore (int Dieone , int Dietwo)
{
return (srand() % 5) + 1 , (srand() % 5) + 1;
}