你好,我正在尝试创建一个在线形式的一个小纸面算命员。这是WIP代码,我已经对它进行了大部分调试,但是我一直收到这两个错误
fortune.c:58:3: error: function definition is not allowed here
fortune.c:79:4: error: function definition is not allowed here我已经查了很多这个问题,它一直告诉我,你必须在main之外定义函数,因为它们是全局的,或者其他什么的,但是我已经在主函数之外,在它开始之前,用前几行调用了它们。我还试着把整个代码放在最上面,但在我看来,它看起来很难看,并导致了20个bug。我只是松了一口气,把所有的错误降到个位数lol。因此,这是代码,任何帮助都将不胜感激。这是我第一次编码。砖块
#include <stdio.h>
#include <string.h>
void fortune1(void);
void fortune2(void);
int main (void)
{
int fort;
int tune;
// get color
char color; // []?
printf("Color?\n");
scanf("%s", &color);
int count;
count = strlen(&color);
{
if(count % 2 == 0)
int num1;
printf("Number?\n");
scanf("%d", &num1);
if(num1 % 2 == 0)
{
fortune1();
}
else
{
fortune2();
}
}
{
int num2; // []?
printf("Number?\n");
scanf("%d", &num2);
if(num2 % 2 == 0)
{
fortune1();
}
else
{
fortune2();
}
}
}
// fortune1 function
void fortune1(void)
{
do
{
int fort;
printf("Fortune?\n");
scanf("%d", &fort);
} while (fort < 5 || fort > 0); //must be in range 1-4
if(fort = 1);
printf("fortune1");
if(fort = 2);
printf("fortune2");
if(fort = 3);
printf("fortune3");
if(fort = 4);
printf("fortune4");
}
// fortune2 function
void fortune2(void)
{
do
{
int tune;
printf("Fortune?\n");
scanf("%d", &tune);
} while (tune < 9 || tune > 4)
if(tune = 5);
printf("fortune5");
if(tune = 6);
printf("fortune6");
if(tune = 7);
printf("fortune7");
if(tune = 8);
printf("fortune8");
}
}
'''发布于 2020-07-21 05:06:57
#include <stdio.h>
#include <string.h>
void fortune1(void);
void fortune2(void);
int main (void)
{
int fort;
int tune;
// get color
char color[10]; // []? if you're using string, then use array
printf("Color?\n");
scanf("%s", &color);
int count;
count = strlen(color); //if u use &, you'll count the variable address
if(count % 2 == 0)
{
int num1;
printf("Number1?\n");
scanf("%d", &num1);
if(num1 % 2 == 0)
{
fortune1();
}
else
{
fortune2();
}
}
else
{
//i dunno if this part is inside if or else
int num2; // []?
printf("Number2?\n");
scanf("%d", &num2);
if(num2 % 2 == 0)
{
fortune1();
}
else
{
fortune2();
}
}
}
// fortune1 function
void fortune1(void)
{
int fort;
do
{
printf("Fortune1?\n");
scanf("%d", &fort);
} while (fort >= 5 || fort <= 0); //must be in range 1-4
// i change the condition iniside while, because if not, the code will always looping
if(fort == 1) // == not =
printf("fortune1");
if(fort == 2)
printf("fortune2");
if(fort == 3)
printf("fortune3");
if(fort == 4)
printf("fortune4");
//don't use ; after if
}
// fortune2 function
void fortune2(void)
{
int tune;
do
{
printf("Fortune2?\n");
scanf("%d", &tune);
} while (tune >= 9 || tune <= 4); //; after while in do while
if(tune == 5)
printf("fortune5");
if(tune == 6)
printf("fortune6");
if(tune == 7)
printf("fortune7");
if(tune == 8)
printf("fortune8");
}如果我错了请告诉我
https://stackoverflow.com/questions/63007101
复制相似问题