c - 带有循环的 C 程序中的老虎机
问题描述
我正在尝试制作随机数和循环来创建老虎机。这是我课程的最终项目的一部分。一旦这是工作程序,我也正在尝试制作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|
解决方案
您的左括号和右括号{
不正确。
在 main 中,您没有关闭while
循环并且在函数中有一个额外的右括号fnSlot1
此类问题可以通过一致的缩进方案轻松解决。在您的程序中,每个缩进都有不同的空格。
推荐阅读
- google-sheets - 服务“sheets.googleapis.com”的“每位用户每 100 秒的读取请求”
- javascript - 如何避免库中的默认错误
- node.js - 指定的选择器不匹配 DOM 树中的任何元素
- r - R:河流物种的物种分布建模 - 所有坐标都不落在栅格单元中
- gremlin - 有没有办法知道 gremlin 查询是读查询还是写查询
- mongodb - 在 mongodb 的不同集合中搜索覆盖的字段
- php - PHP substr 不剥离文件扩展名
- multithreading - 如何在 HostedService 中引发事件并在 Blazor 组件中使用它?
- python - 从 Azure Blob 存储加载文件内容
- python - 使用 exec() 获取类实例