When do we get type mismatch in redeclaration error in c?
Answers
Answered by
0
First of all, this snippet
printf("Enter time:"); scanf("%d", &t);
shouldn't work as you haven't declared tas an integer, so just declare t on the line above like such.
int a, c, t;
You also didn't declare any of the variables in your si function. When you pass the c variable, it never gets initialized.
What will help your type mismatch error is a forward declaration of the si function.
By adding the line float si(int a, int c, float b); to the top of your program (above main), you let the compiler know what type of function si is, as well as what arguments to expect.
Here is my best attempt to fix up the code:
#include <stdio.h> #include <conio.h> float si(int a, int c, float b); float si(int a, int c, float b){ float f; f=(a*b*c/100); return f; } void main(){ int a, c; float b, d; printf("Enter principle value :"); scanf("%d", &a); printf("Enter rate :"); scanf("%f", &b); printf("Enter time:"); scanf("%d", &c); d = si(a,c,b); printf("The simple interest is %f", d); }
printf("Enter time:"); scanf("%d", &t);
shouldn't work as you haven't declared tas an integer, so just declare t on the line above like such.
int a, c, t;
You also didn't declare any of the variables in your si function. When you pass the c variable, it never gets initialized.
What will help your type mismatch error is a forward declaration of the si function.
By adding the line float si(int a, int c, float b); to the top of your program (above main), you let the compiler know what type of function si is, as well as what arguments to expect.
Here is my best attempt to fix up the code:
#include <stdio.h> #include <conio.h> float si(int a, int c, float b); float si(int a, int c, float b){ float f; f=(a*b*c/100); return f; } void main(){ int a, c; float b, d; printf("Enter principle value :"); scanf("%d", &a); printf("Enter rate :"); scanf("%f", &b); printf("Enter time:"); scanf("%d", &c); d = si(a,c,b); printf("The simple interest is %f", d); }
Similar questions