Hello I am practicing my knowledge in C language I am trying to make a simple calculator but I encountered this warning Implicit Declaration of Function
but the function that I called has been executed. I tried to fix it with this void start();
but the function did not execute.
Successful executed the function start();
but have a implicit warning:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void addition()
{
int vala, valb, resu;
system("cls");
printf("SiMPLE CALCULATOR 1.0a\n");
printf("ADDITION\n");
printf("\n");
printf("Enter the first value of addend: ");
scanf("%d", &vala);
printf("Enter the second value of addend: ");
scanf("%d", &valb);
resu=vala+valb;
printf("The sum of %d and %d is: %d\n", vala, valb, resu);
printf("PRESS [ANY KEY] TO CONTINUE...");
getch();
start(); \\THIS CODE
}
void start()
{
char ope;
system("cls");
printf("SiMPLE CALCULATOR 1.0a\n");
printf("What operation will be used:");
scanf("%s", &ope);
if (ope == 'a')
{
addition();
}
else if (ope == 'b')
{
printf("bbbbbbbbbbbb\n");
}
else
{
printf("ccccccccccc\n");
}
}
int main()
{
int choices;
printf("SiMPLE CALCULATOR 1.0a\n");
printf("choose an option:");
scanf("%d", &choices);
if (choices == 1)
{
start();
}
getch();
return 0;
}
Failed to execute the function void start();
start but no implicit warning:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void addition()
{
int vala, valb, resu;
system("cls");
printf("SiMPLE CALCULATOR 1.0a\n");
printf("ADDITION\n");
printf("\n");
printf("Enter the first value of addend: ");
scanf("%d", &vala);
printf("Enter the second value of addend: ");
scanf("%d", &valb);
resu=vala+valb;
printf("The sum of %d and %d is: %d\n", vala, valb, resu);
printf("PRESS [ANY KEY] TO CONTINUE...");
getch();
void start(); \\THIS CODE
}
void start()
{
char ope;
system("cls");
printf("SiMPLE CALCULATOR 1.0a\n");
printf("What operation will be used:");
scanf("%s", &ope);
if (ope == 'a')
{
addition();
}
else if (ope == 'b')
{
printf("bbbbbbbbbbbb\n");
}
else
{
printf("ccccccccccc\n");
}
}
int main()
{
int choices;
printf("SiMPLE CALCULATOR 1.0a\n");
printf("choose an option:");
scanf("%d", &choices);
if (choices == 1)
{
start();
}
getch();
return 0;
}
start()
is declare after addition()
, but in addition()
you call start()
, so the compiler don't know what start()
is. Also, in start()
you also call addition()
, so the best way to reslove this is using forward declaration:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void start(void); /* forward declaration */
void addition(void); /* forward declaration */
void addition(void)
{
int vala, valb, resu;
system("cls");
printf("SiMPLE CALCULATOR 1.0a\n");
printf("ADDITION\n");
printf("\n");
printf("Enter the first value of addend: ");
scanf("%d", &vala);
printf("Enter the second value of addend: ");
scanf("%d", &valb);
resu=vala+valb;
printf("The sum of %d and %d is: %d\n", vala, valb, resu);
printf("PRESS [ANY KEY] TO CONTINUE...");
getch();
start();
}
void start(void)
{
char ope;
system("cls");
printf("SiMPLE CALCULATOR 1.0a\n");
printf("What operation will be used:");
scanf("%s", &ope);
if (ope == 'a')
{
addition();
}
else if (ope == 'b')
{
printf("bbbbbbbbbbbb\n");
}
else
{
printf("ccccccccccc\n");
}
}