请帮忙,当我要求用户输入继续使用scanf和printf时,我似乎无法让do-while循环循环。可能是wipe_buffer吗?我似乎无法做到这一点,我只需要完成循环,这应该是主要的功能。编码新手和这个网站请不要太苛刻。请和谢谢。
#include <stdio.h>
#include <stdlib.h>
void wipe_buffer(void);
int main(int argc, char* argv[])
{
char play1;
char play2;
char cont;
do{
printf("Player one pick Rock, Paper, or Scissors\n");
scanf(" %c", &play1);
wipe_buffer();
printf("Player two pick Rock, Paper, or Scissors\n");
scanf(" %c", &play2);
wipe_buffer();
switch(play1)
{
case 'r':
if(play2 == 'p' || play2 == 'P')
{
printf("Paper Covers Rock\n");
printf("Player two wins\n");
}
if(play2 == 's' || play2 == 'S')
{
printf("Rock Breaks Scissors\n");
printf("Player one wins\n");
}
if(play2 == 'r' || play2 == 'R')
{
printf("Draw, Nobody wins\n");
}
break;
case 'R':
if(play2 == 'p' || play2 == 'P')
{
printf("Paper Covers Rock\n");
printf("Player two wins\n");
}
if(play2 == 's' || play2 == 'S')
{
printf("Rock Breaks Scissors\n");
printf("Player one wins\n");
}
if(play2 == 'r' || play2 == 'R')
{
printf("Draw, Nobody wins\n");
}
break;
case 'P':
if(play2 == 'p' || play2 == 'P')
{
printf("Draw, Nobody wins\n");
}
if(play2 == 's' || play2 == 'S')
{
printf("Scissors cuts Paper\n");
printf("Player two wins\n");
}
if(play2 == 'r' || play2 == 'R')
{
printf("Paper covers rock\n");
}
break;
case 'p':
if(play2 == 'p' || play2 == 'P')
{
printf("Draw, Nobody wins\n");
}
if(play2 == 's' || play2 == 'S')
{
printf("Scissors cuts Paper\n");
printf("Player two wins\n");
}
if(play2 == 'r' || play2 == 'R')
{
printf("Paper covers rock\n");
}
break;
case 's':
if(play2 == 'p' || play2 == 'P')
{
printf("Scissors Cuts Paper\n");
printf("Player one wins\n");
}
if(play2 == 's' || play2 == 'S')
{
printf("Draw, Nobody wins\n");
}
if(play2 == 'r' || play2 == 'R')
{
printf("Rock breaks Scissors\n");
printf("Player two wins\n");
}
break;
case 'S':
if(play2 == 'p' || play2 == 'P')
{
printf("Scissors Cuts Paper\n");
printf("Player one wins\n");
}
if(play2 == 's' || play2 == 'S')
{
printf("Draw, Nobody wins\n");
}
if(play2 == 'r' || play2 == 'R')
{
printf("Rock breaks Scissors\n");
printf("Player two wins\n");
}
break;
}
printf("Do you wish to continue?\n");
scanf(" &c", &cont);
wipe_buffer();
}while(cont == 'y' || cont == 'Y');
}
void wipe_buffer(void)
{
char t;
scanf("%c", &t);
while(t != '\n' )
{
scanf("%c", &t);
}
return;
}