带有循环的C程序中的老虎机

时间:2018-11-30 04:06:32

标签: c function loops

我正在尝试制作随机数和循环来创建老虎机。这是我课程最终项目的一部分。一旦这个程序生效,我也将尝试创建curses库。我正在使用Code::Blocks软件下载下面的错误消息,我可以下载这些软件以免费使用。我不知道这怎么不能正常工作...有人可以帮忙吗?

#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();
    while (1) {
        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()
{
    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);
}

通过代码::块

进行编译
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|16|undefined reference to `fnSlotMachine'|
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|18|undefined reference to `fnSlot1'|
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|60|undefined reference to `fnGotoXY'|
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|63|undefined reference to `fnGotoXY'|
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|65|undefined reference to `fnGotoXY'|
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|73|undefined reference to `fnGotoXY'|
C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|76|undefined reference to `fnGotoXY'|
obj\Debug\main.o:C:\Users\Admin\Documents\PROGRAMMING\runner\main.c|78|more undefined references to `fnGotoXY' follow|

1 个答案:

答案 0 :(得分:0)

您的左括号{不正确。

在一般情况下,您尚未关闭while循环,并且在函数fnSlot1中有一个额外的右括号

一致的缩进方案可以很容易地发现这类问题。在程序中,每个缩进都有不同的空格。