Conflicting Types Error

Hi all. I am getting an error conflicting types for 'dispense' at line 11. Not quite sure how to fix this problem. Any ideas?

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
 #pragma warning (disable:4996)
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int dispense(int amount, int *ptwenty, int *pten, int *pfive);

int main(void)
{
    int amount;
    int dispense(int, int, int, int);
    int ones;
    int ten;
    int twenty;
    int five;
    ones = dispense(amount, &twenty, &ten, &five);
    
     printf("%s\n","*****Welcome to Central Banking ATM*****");
     printf("%s\n","Enter the amount you'd like to withdraw: ");
     printf("%s\n","NOTE: It must be a multiple of 5.");
     scanf("%d",&amount);
     printf("%s%d\n","Number of 20s: ",twenty);
     printf("%s%d\n","Number of 10s: ",ten);
     printf("%s%d\n","Number of 5s: ",five);
     printf("%s\n","Thank you for your business!");
    
     return 0;
     }

int dispense(int amount, int *ptwenty, int *pten, int *pfive)
{
    int amt = amount;
    *ptwenty = amt / 20;
    amount = amt % 20;
     *pten = amt / 10;
     amount = amt % 10;
     *pfive = amt / 5;
     return amt % 5;
}
Last edited on
Yes turn line 11 into this.

 
    int dispense(int, int*, int*, int*);
Remove Line 11, You already have a function prototype at line 6 so you can use your function dispense in main() without need of an invalid line 11

You are passing a garbage value amount to function dispense which will give you incorrect values for five ten and twenty since amount is not initialized.

Cut Line 16 and insert it after line 21 like this:

1
2
scanf(" %d", &amount);
ones = dispense(amount, &twenty, &ten, &five);
Last edited on
Topic archived. No new replies allowed.