C中的老虎机(gotoxy) #包括 #包括 #包括 int intSlot1、intSlot2、intSlot3; void fngtoxy(短x,短y); void fnSlotMachine(); void fnSlot1(); void fnSlot2(); void fnSlot3(); int main(){ srand(时间(0)); fnSlotMachine(); fnSlot1(); fnSlot2(); fnSlot3(); } 空fnGotoXY(短x,短y){ 坐标pos={x,y}; 设置控制台或位置(GetStdHandle(标准输出手柄),位置); } void fnSlotMachine(){ fnGotoXY(5,5); printf(“x^------------------^x\n”); printf(“oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo; printf(“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu/\n”); printf(“/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$\\\\\\\”; fnGotoXY(5,12); printf(“”); } void fnSlot1(){ 而(1){ 睡眠(50); fnGotoXY(5,9); intSlot1=rand()%9; printf(“|%i%i%i |\n”,intSlot1,intSlot1,intSlot1); fnGotoXY(2,10); printf(“|%i%i%i |\n”,intSlot1,intSlot1,intSlot1); fnGotoXY(2,11); printf(“|%i%i%i |”,intSlot1,intSlot1,intSlot1); } } void fnSlot2(){ 而(1){ 睡眠(50); fnGotoXY(17,9); intSlot2=rand()%9; printf(“|%i%i%i |\n”,intSlot2,intSlot2,intSlot2); fnGotoXY(17,10); printf(“|%i%i%i |\n”,intSlot2,intSlot2,intSlot2); fnGotoXY(17,11); printf(“|%i%i%i |”,intSlot2,intSlot2,intSlot2); } } void fnSlot3(){ 而(1){ 睡眠(50); fnGotoXY(27,9); intSlot3=rand()%9; printf(“|%i%i%i |\n”,intSlot3,intSlot3,intSlot3); fnGotoXY(27,10); printf(“|%i%i%i |\n”,intSlot3,intSlot3,intSlot3); fnGotoXY(27,11); printf(“|%i%i%i |”,intSlot3,intSlot3,intSlot3); } }

C中的老虎机(gotoxy) #包括 #包括 #包括 int intSlot1、intSlot2、intSlot3; void fngtoxy(短x,短y); void fnSlotMachine(); void fnSlot1(); void fnSlot2(); void fnSlot3(); int main(){ srand(时间(0)); fnSlotMachine(); fnSlot1(); fnSlot2(); fnSlot3(); } 空fnGotoXY(短x,短y){ 坐标pos={x,y}; 设置控制台或位置(GetStdHandle(标准输出手柄),位置); } void fnSlotMachine(){ fnGotoXY(5,5); printf(“x^------------------^x\n”); printf(“oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo; printf(“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu/\n”); printf(“/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$\\\\\\\”; fnGotoXY(5,12); printf(“”); } void fnSlot1(){ 而(1){ 睡眠(50); fnGotoXY(5,9); intSlot1=rand()%9; printf(“|%i%i%i |\n”,intSlot1,intSlot1,intSlot1); fnGotoXY(2,10); printf(“|%i%i%i |\n”,intSlot1,intSlot1,intSlot1); fnGotoXY(2,11); printf(“|%i%i%i |”,intSlot1,intSlot1,intSlot1); } } void fnSlot2(){ 而(1){ 睡眠(50); fnGotoXY(17,9); intSlot2=rand()%9; printf(“|%i%i%i |\n”,intSlot2,intSlot2,intSlot2); fnGotoXY(17,10); printf(“|%i%i%i |\n”,intSlot2,intSlot2,intSlot2); fnGotoXY(17,11); printf(“|%i%i%i |”,intSlot2,intSlot2,intSlot2); } } void fnSlot3(){ 而(1){ 睡眠(50); fnGotoXY(27,9); intSlot3=rand()%9; printf(“|%i%i%i |\n”,intSlot3,intSlot3,intSlot3); fnGotoXY(27,10); printf(“|%i%i%i |\n”,intSlot3,intSlot3,intSlot3); fnGotoXY(27,11); printf(“|%i%i%i |”,intSlot3,intSlot3,intSlot3); } },c,C,所以,我的问题是关于gotoxy的。在我放入while(1)循环后,其他插槽没有打印。希望得到一些回应。提前谢谢 从fnSlotN函数中删除while(1)循环,改为: #include <stdio.h> #include <time.h> #include <windows.h> int intSlot1, intSlot2, intSlot3; void fnGotoXY(short x, short y); void fnSlotMachine()

所以,我的问题是关于gotoxy的。在我放入
while(1)
循环后,其他插槽没有打印。希望得到一些回应。提前谢谢

fnSlotN
函数中删除
while(1)
循环,改为:

#include <stdio.h>
#include <time.h>
#include <windows.h>

int intSlot1, intSlot2, intSlot3;

void fnGotoXY(short x, short y);
void fnSlotMachine();
void fnSlot1();
void fnSlot2();
void fnSlot3();

int main(){

        srand( time(0) );
        fnSlotMachine();
        fnSlot1();
        fnSlot2();
        fnSlot3();

}

void fnGotoXY(short x, short y){

        COORD pos = {x, y};
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);

}

void fnSlotMachine(){

        fnGotoXY(5, 5);
        printf(" x^---------------------------^x\n");
        printf("      |oOoOoOoOoOoOoOoOoOoOoOoOoOoOo|\n");
        printf("      \\_____________________________/\n");
        printf("      /__$$$__\\  /__$$$__\\  /__$$$__\\");
        fnGotoXY(5, 12);
        printf(" <*^*^*^*>  <*^*^*^*>  <*^*^*^*>");


}

void fnSlot1(){

        while(1){
                Sleep(50);
                fnGotoXY(5, 9);
                intSlot1 = rand() % 9;
                printf(" | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
                fnGotoXY(2, 10);
                printf("    | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
                fnGotoXY(2, 11);
                printf("    | %i %i %i |",   intSlot1, intSlot1, intSlot1);
        }      
}

void fnSlot2(){

        while(1){
                Sleep(50);
                fnGotoXY(17, 9);
                intSlot2 = rand() % 9;
                printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
                fnGotoXY(17, 10);
                printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
                fnGotoXY(17, 11);
                printf("| %i %i %i |",   intSlot2, intSlot2, intSlot2);
        }
}

void fnSlot3(){

        while(1){
                Sleep(50);
                fnGotoXY(27, 9);
                intSlot3 = rand() % 9;
                printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
                fnGotoXY(27, 10);
                printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
                fnGotoXY(27, 11);
                printf("| %i %i %i |",   intSlot3, intSlot3, intSlot3);
        }
}

在所有函数中都有无限个循环。如果您输入一个函数,则永远不会返回

考虑将其置于主功能中

while(1)
{
    fnSlot1();
    fnSlot2();
    fnSlot3();
}
#包括
#包括
...
int main(){
srand(时间(0));
fnSlotMachine();
而(1){
fnSlot1();
fnSlot2();
fnSlot3();
}
}
...    
void fnSlot1(){
睡眠(50);
fnGotoXY(5,9);
intSlot1=rand()%9;
printf(“|%i%i%i |\n”,intSlot1,intSlot1,intSlot1);
fnGotoXY(2,10);
printf(“|%i%i%i |\n”,intSlot1,intSlot1,intSlot1);
fnGotoXY(2,11);
printf(“|%i%i%i |”,intSlot1,intSlot1,intSlot1);
}
void fnSlot2(){
睡眠(50);
fnGotoXY(17,9);
intSlot2=rand()%9;
printf(“|%i%i%i |\n”,intSlot2,intSlot2,intSlot2);
fnGotoXY(17,10);
printf(“|%i%i%i |\n”,intSlot2,intSlot2,intSlot2);
fnGotoXY(17,11);
printf(“|%i%i%i |”,intSlot2,intSlot2,intSlot2);
}
void fnSlot3(){
睡眠(50);
fnGotoXY(27,9);
intSlot3=rand()%9;
printf(“|%i%i%i |\n”,intSlot3,intSlot3,intSlot3);
fnGotoXY(27,10);
printf(“|%i%i%i |\n”,intSlot3,intSlot3,intSlot3);
fnGotoXY(27,11);
printf(“|%i%i%i |”,intSlot3,intSlot3,intSlot3);
}

而(1)
是一个无限循环。您似乎没有打破它,但为什么其他两个插槽没有打印?因为您在
fnSlot1()
中的第一个无限循环永不结束。。现在它起作用了。非常感谢,超级酷的家伙!为什么你对一个无止境的循环没有结束感到惊讶!?我就是这么做的。谢谢您的回复,好心的先生!
#include <stdio.h>
#include <time.h>
...

int main(){

        srand( time(0) );
        fnSlotMachine();
        while(1) {
          fnSlot1();
          fnSlot2();
          fnSlot3(); 
        }
}

...    
void fnSlot1(){

            Sleep(50);
            fnGotoXY(5, 9);
            intSlot1 = rand() % 9;
            printf(" | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
            fnGotoXY(2, 10);
            printf("    | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
            fnGotoXY(2, 11);
            printf("    | %i %i %i |",   intSlot1, intSlot1, intSlot1);

}

void fnSlot2(){


            Sleep(50);
            fnGotoXY(17, 9);
            intSlot2 = rand() % 9;
            printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
            fnGotoXY(17, 10);
            printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
            fnGotoXY(17, 11);
            printf("| %i %i %i |",   intSlot2, intSlot2, intSlot2);

}

void fnSlot3(){


            Sleep(50);
            fnGotoXY(27, 9);
            intSlot3 = rand() % 9;
            printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
            fnGotoXY(27, 10);
            printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
            fnGotoXY(27, 11);
            printf("| %i %i %i |",   intSlot3, intSlot3, intSlot3);

}