C程序中的老虎机带循环

问题描述 投票:0回答:1

我正在尝试制作随机数字和循环来创建老虎机。这是我课程最终项目的一部分。一旦这是工作程序,我也试图制作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);
}

Code :: Blocks的编译器:

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|
c function loops
1个回答
0
投票

您的开始和结束括号{不正确。

在主要你没有关闭while循环并在功能fnSlot1有一个额外的结束括号

这种问题可以通过一致的缩进方案轻松捕获。在您的程序中,每个缩进都有不同的空格。

© www.soinside.com 2019 - 2024. All rights reserved.