I'm trying to write a function in C and call it in my main function. The problem I'm having is that it seems to not be returning the values to the main function.
The functions code:
int calculateCoins(int x, int y, int z)
{
while ((x - y) >= 0)
{
x = x - y;
z++;
}
return x;
return z;
}
How I call the function in main:
calculateCoins(totalCents, 25, numberOfCoins);
calculateCoins(totalCents, 10, numberOfCoins);
calculateCoins(totalCents, 5, numberOfCoins);
calculateCoins(totalCents, 1, numberOfCoins);
Basically I need the function to return it's x and z values to totalCents and numberOfCoins. I'm not sure how to do this. I've tested the function with printf and it takes in the correct values for x, y, and z and completes the while loop correctly. However it then does not return the values afterwards. The only information I could find searching online was about how maybe the compiler was recognizing that x and z are not used anywhere else so it's not returning them. But the variables that the x and y variables are for, are used.
Can anyone help me with this? I'm just in the early stages of learning programming with no prior experience, so please forgive me if the answer is obvious or if my code is poorly written. Thank you.
Aucun commentaire:
Enregistrer un commentaire