Hello. I wrote this code to solve the common change question requiring the use of cases. It worked at first, I ran through it several times. Then for some reason it started crashing my compiler and I don't know why. I'm using Code::Blocks. I'm getting two message when I compile it but don't try to run it:
|24|warning: passing argument 3 of 'change' from incompatible pointer type [enabled by default]|
|18|note: expected 'int *' but argument is of type 'int **'|
The code is as follows:
Code:
#include <stdio.h>
int main()
{
/*Declare variables*/
float total;
int quarters, dimes, nickels, pennies;
/*Function prototype*/
void change (float total, int *quarters, int *dimes, int *nickels, int *pennies)
{ /* First amount*/
total =1.88;
/*Call change function*/
change(total, &quarters, &dimes, &nickels, &pennies);
printf("\nTotal value: $%0.2f\n", total);
printf(" Quarters: %d\n", quarters);
printf(" Dimes: %d\n", dimes);
printf(" Nickels: %d\n", nickels);
printf(" Pennies: %d\n", pennies);
}
{ /*Second amount*/
total =0.32;
/*Call change function*/
change(total, &quarters, &dimes, &nickels, &pennies);
printf("\nTotal value: $%0.2f\n", total);
printf(" Quarters: %d\n", quarters);
printf(" Dimes: %d\n", dimes);
printf(" Nickels: %d\n", nickels);
printf(" Pennies: %d\n", pennies);
}
{ /*User entered amount*/
printf("\n\nEnter the amount money in change that you are carrying:\n");
scanf(" %f", &total);
/*Call change function*/
change(total, &quarters, &dimes, &nickels, &pennies);
printf("\nTotal value entered: $%0.2f\n", total);
printf(" Quarters: %d\n", quarters);
printf(" Dimes: %d\n", dimes);
printf(" Nickels: %d\n", nickels);
printf(" Pennies: %d\n", pennies);
}
return 0;
} /* end of main()*/
/*This is the change function*/
void change (float total, int *quarters, int *dimes, int *nickels, int *pennies)
{
if(total >= 0.25);
*quarters = (total/0.25);
if(total >=0.10);
*dimes = (total - (*quarters * 0.25))/0.10;
if(total >= 0.05);
*nickels = (total - (*quarters * 0.25)-(*dimes * 0.10))/0.05;
if(total < 0.05);
*pennies = (total - (*quarters * 0.25)-(*dimes * 0.10)-
(*nickels * 0.05))/0.01 + 0.005;
return 0;
}
Could someone please give me some idea why this is now crashing my compiler and not running when it worked before? Thanks in advance.
Bridget