Gcc gives the error "functions.c: In function 'retryop': functions.c:109:3: warning: implicit declaration of function 'main' [-Wimplicit-function-declaration] main(); ^~~~"
I'm creating a function that calls back to main to restart the file, but i don't know how to have it return since main is declared after my functions file. Any help with this would be very greatly appreciated.
Main.c
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include "functions.c"
int main()
{
setup();
char type;
double number1;
double number2;
int temp;
bool retry;
printf("Please choose what operation you would like to do ( +, -, *,/, or R): \n");
scanf("%c", &type);
if (type == '+')
{
setup();
printf("Addition\n");
printf("\n");
printf("Please enter Addend 1:");
scanf("%lf", &number1);
printf("Please enter Addend 2:");
scanf("%lf", &number2);
double answer = number1 + number2;
printf("The Sum is: %f", answer);
retryop();
}
else if (type == '-')
{
setup();
printf("Subtraction\n");
printf("\n");
printf("Please enter Your Minuend:");
scanf("%lf", &number1);
printf("Please enter Your Subtrahend:");
scanf("%lf", &number2);
double answer = number1 - number2;
printf("The Differnce is: %f", answer);
retryop();
}
else if (type == '*')
{
setup();
printf("Muliplication\n");
printf("\n");
printf("Please enter Factor 1:");
scanf("%lf", &number1);
printf("Please enter Factor 2:");
scanf("%lf", &number2);
double answer = number1 * number2;
printf("Your Product is: %f", answer);
retryop();
}
else if (type == '/')
{
setup();
printf("Division\n");
printf("\n");
printf("Please enter your divadend:");
scanf("%lf", &number1);
printf("Please enter your divisor:");
scanf("%lf", &number2);
double answer = number1 / number2;
printf("Your quotient is: %f", answer);
retryop();
}
else if (type == 'R')
{
setup();
int maxValue;
srand(time(NULL));
printf("Please enter your max value:");
scanf("%i", &maxValue);
int random = (rand() % (maxValue + 1));
printf("Here is your random number: %i", random);
retryop();
}
else if (type == 'r')
{
setup();
int maxValue;
srand(time(NULL));
printf("Please enter your max value:");
scanf("%i", &maxValue);
int random = (rand() % (maxValue + 1));
printf("Here is your random number: %i\n", random);
retryop();
}
else
{
setup();
printf("Please Re-run your program and enter a valid Operator\n");
system("pause");
Main();
}
}
Functions.c
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
char type;
double number1;
double number2;
double answer;
bool retry;
char temp;
void setup()
{
system("cls");
}
int typeselect()
{
printf("Please choose what operation you would like to do ( +, -, *,/, or R): \n");
scanf("%c", &type);
return type;
}
int retryop()
{
printf("Would you like to do this again? [Y/N]");
scanf("%i", &temp);
if (temp == 'Y')
{
system("pause");
Main();
}
else if (temp == 'y')
{
system("pause");
Main();
}
else if(temp == 'N')
{
system("pause");
return 0;
}
else if(temp == 'n')
{
system("pause");
return 0;
}
else
{
system("pause");
return 0;
}
}
main()
is different thanMain()
– Cidmain
. Write seperate function(s) for that. And more generally, functions need to be declared before they are used, see: warning: implicit declaration of function – kaylummain()
infunctions.c
– klutt