Please Help!! Cant see what im doing wrong

Making a program to calculate change and I cant figure out where ive gone wrong
Program is ment to accept a value from 5-95 and as a multiple of 5 and output the number of coins needed to make up the ammount. valid coins are 50, 20, 10 and 5.


#include<stdio.h>
#include<ctype.h>

void GetCents(int &change)
{
printf("This program will calculate change. Please enter your change betweenn 95-5 and as a multiple of 5.\n");
scanf("%d%*c", &change);

return;
}

int CalcChange(int &coin50, int &coin20, int &coin10, int &coin5)
{
int change;

while(change% 5==0 && change >=5 && change <= 95)
{
if (change >= 50)
{
coin50++;
change = change - 50;
}
else
if (change >= 20)
{
coin20++;
change = change - 20;
}
else
if (change >= 10)
{
coin10++;
change = change - 10;
}
else
if (change >= 5)
{
coin5++;
change = change - 5;
}
else
printf("Please enter an integer in the range of 5-95 and a multiple of 5.\n");
}
return(change);
}

void PrintResults()
{
int coin50, coin20, coin10, coin5;

printf("%d\n", coin50);
printf("%d\n", coin20);
printf("%d\n", coin10);
printf("%d\n", coin5);

return;
}


int main()
{
int change;
int coin50, coin20, coin10, coin5;

GetCents(change);
CalcChange(coin50, coin20, coin10, coin5);
PrintResults();

return(0);
}


When I try to run the program I get random jumble of numbers printed out!
I would appreciate any help!





This function is invalid and has no sense because you are processing local variable change that was not even initialized

int CalcChange(int &coin50, int &coin20, int &coin10, int &coin5)
{
int change;

while(change% 5==0 && change >=5 && change <= 95)
{
Last edited on
I initialized change to = 0

int CalcChange(int &coin50, int &coin20, int &coin10, int &coin5)
{
int change = 0;

while(change% 5==0 && change >=5 && change <= 95)
{


but I still get the same problem with the output of the program being random jumble of numbers.

Also, am i using the increment operator in the correct way?
Last edited on
As I said this function has no sense. Instead of processing of the local variable which always equal to 0 you should pass to the function the value you entered.
Topic archived. No new replies allowed.