function problems

I am attempting to use functions but keep getting errors any help would be great

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#define TAX 0.05

int main()
{
    totalCalc();
    system("pause");
    return 0;
}

void totalCalc(void)
{
    float tax, value, total;

    printf("Please enter the subtotal: ");
    scanf("%f", &value);
    tax = taxCalc(value);
    total = tax + value;
    printf("Subtotal  %.2f", value);
    printf("tax total %.2f", tax);
    printf("Total     %.2f", total);
    
}

float taxCalc(float subtotal)
{
    float output, tax2;
    
    fflush(stdin);
    printf("Please enter the Tax rate [%1.2f]: ", TAX);
    if ((scanf("%c")) == '\n')
    {
        output = subtotal * TAX;
    } else
    {
        scanf("%f", &tax2);
        output = subtotal * tax2;
    }
    
    return output;
}


The errors that I am getting are

13 H:\Desktop\testmultifunc.c conflicting types for 'totalCalc'
7 H:\Desktop\testmultifunc.c previous implicit declaration of 'totalCalc' was here
27 H:\Desktop\testmultifunc.c conflicting types for 'taxCalc'
18 H:\Desktop\testmultifunc.c previous implicit declaration of 'taxCalc' was here
Last edited on
I think you need to declare those functions before int main() function, something like this:

void totalCalc(void);
float taxCalc(float subtotal);
...
...
int main()
{
..
Last edited on
This can't possibly be all of your source code can it? TotalCalc is never declared before it is used on line 7, unless maybe you're just using a slightly crappy compiler because those error messages are quite difficult to decipher when compared to the actual problem
Last edited on
Thanks alex9 that seemed to sort it out. Oh and quirkyusername ya this is all of my source code I was just gettin used to usin func's.
Topic archived. No new replies allowed.