I have one function that getting printing a menue and returning a choice. And another function to calculate 2 numbers that im getting from the user. Now, the calculation is depanding on the choice return from the first function, and im dont really know what is the right way to use 2 different type of functions together…this is both functions:
float calc(float number1, float number2)
{
float answer;
int operand;
operand =get_choice();// problemmmm
}
char get_choice(void)
{
char choice;
printf("Enter the operation of your choice:\n");
printf("a. add s. subtract\n");
printf("m. multiply d. divide\n");
printf("q. quit");
while ((choice = getchar()) != 'q')
{
if (choice != 'a' || choice != 's' || choice != 'm' || choice != 'd')
{
printf("Enter the operation of your choice:\n");
printf("a. add s. subtract\n");
printf("m. multiply d. divide\n");
printf("q. quit");
continue;
}
}
return choice;
}
I got an error saying “implicit function of get_choice is invalid in C99”
That implicit function error probably means that the compiler doesn’t yet know about the
get_choicefunction by the time it reaches the line when it gets called. You can fix this by either.Changing the order you write your functions in. Write get_choice before the calc function
Add a declaration for the get_choice function before the calc function. The declaration would be just the function name and type, without the code:
If you are wondering what the message was about, in C89 undeclared functions were implicitly assumed to return an integer. C99 is stricter and forces you to always declare functions but the error message still refers to the C89 style implicit declarations.