用户想玩多少次c语言游戏

用户想玩多少次c语言游戏,c,C,我正在学习如何写一个游戏,我得到了以下游戏规则 规则1:玩家必须定义一个停止回合的最小数字,这个数字必须大于10 规则2:四舍五入的所有分数都加到总数中 规则3:如果骰子落在1上,则该回合的所有点数将被没收 规则4:第一个得到101分的玩家获胜! 我试图得到的游戏数量输入后,用户输入有多少玩家 我的问题是,每次我输入球员姓名时都会询问用户,这取决于我输入了多少球员 范例 人数:3人 多少场比赛:15场 输入球员姓名:约翰 多少游戏:15我再次输入这个数字我不需要这一行 输入球员姓名:玛丽 多少游

我正在学习如何写一个游戏,我得到了以下游戏规则

规则1:玩家必须定义一个停止回合的最小数字,这个数字必须大于10 规则2:四舍五入的所有分数都加到总数中 规则3:如果骰子落在1上,则该回合的所有点数将被没收 规则4:第一个得到101分的玩家获胜! 我试图得到的游戏数量输入后,用户输入有多少玩家

我的问题是,每次我输入球员姓名时都会询问用户,这取决于我输入了多少球员

范例

人数:3人

多少场比赛:15场

输入球员姓名:约翰

多少游戏:15我再次输入这个数字我不需要这一行

输入球员姓名:玛丽

多少游戏:15我再次输入这个数字我不需要这一行

输入球员姓名:巴里

多少游戏:15我再次输入这个数字我不需要这一行

这是我的问题代码:

//user inputs value of player_num, here, as you have now//

printf_s("Please type in the number of players: ");
scanf_s("%d", &player_num, sizeof(int));
for (i = 0; i < player_num; i++) {
    //user inputs value of num_game, here, as you have now//
    printf_s("Please type in the number of games: ");
    scanf_s("%d", &num_games, sizeof(int));
    num_games = (j = 1, num_games);

    printf_s("Enter the player's first name: ");
    scanf_s("%s", names[i], 25);  
    getchar();               
}
printf_s("\n");
for (i = 0; i < player_num; i++)
    printf_s("\n%s", names[i]);
你的循环有2个扫描,而你只需要一个。把这个

printf_splese键入游戏数:; scanf_s%d,&num_游戏,sizeofint; num_games=j=1,num_games

在你的线圈前面,而不是在它里面

for (i = 0; i < player_num; i++) {

  //user inputs value of num_game, here, as you have now//
  printf_s("Please type in the number of games: ");  // no need for this in the loop
  scanf_s("%d", &num_games, sizeof(int));            // no need for this in the loop   
  num_games = (j = 1, num_games);                    // no need for this in the loop


  printf_s("Enter the player's first name: ");
  scanf_s("%s", names[i], 25);  
  getchar();               
}

它一再要求您输入游戏数的原因是因为您将printf和scanf语句放入了循环中

for (i = 0; i < player_num; i++) {
printf_s("Please type in the number of games: ");//this
scanf_s("%d", &num_games, sizeof(int));//this
num_games = (j = 1, num_games); //including this

printf_s("Enter the player's first name: ");// also this
scanf_s("%s", names[i], 25);  // and this
getchar();
}
的确如此

每次输入玩家姓名时询问用户,具体取决于输入方式 你输入了很多玩家 因为您已经在循环中输入了这些行


对代码进行结构化,使其与您的需求相匹配。您可以改进您的代码,但这是一个全局性的好问题。我把这句话从循环中去掉了。现在它崩溃了,但我决定我需要改变这个特定循环的名称,并利用这个错误,将其转化为游戏中的一个条件,它会要求用户以最小数量停止他们的循环。它实际上并不能解决我按以下顺序提问的问题。问问有多少玩家。必须多于1名玩家2。多少场比赛只问一次3。用户名被询问的次数与数字1被输入的次数相同4。最小停止次数与输入数字1的次数相同,但此处输入的数字必须大于10@ElijahCeeney你没有表现出一个MCVE。我只能指出你展示的代码中的问题是什么……没关系,我解决了问题,谢谢。我不知道MCVE是什么。我对这一切都了如指掌。这个问题的指出帮助我解决了这个问题
printf_s("Please type in the number of players: ");
scanf_s("%d", &player_num, sizeof(int));
printf_s("Please type in the number of games: ");
scanf_s("%d", &num_games, sizeof(int));
num_games = (j = 1, num_games);