# Thread: Help fixing my cash register program.

1. ## Help fixing my cash register program.

I need help making a simple cash register program which a user inputs a number and the program puts the amount of coins and of what value excluding pennies. for example if i enter 90 it should output 1 of 50, 2 of 20, 0 of 10 and 0 of 5.

i have written two separate programs which both dont work.

this one refuses to compile.
Code:
```#include<stdio.h>

void Getnum(int num)
{
printf("Please enter a number between 5 and 95 in cents\n");
scanf("%d%*c", &num);
}

void DoCalc(int &num, int value)
{
value = 0;

while(num >= 50)
{
num = num - 50;
value++;
}

while(num >= 20)
{
num = num - 20;
value++;
}

while(num >= 10)
{
num = num - 10;
value++;
}

while(num >= 5)
{
num = num - 50;
value++;
}
return;
}

void PrintCal(int &value)
{
printf("(Fifty: %d\n" ,value);
printf("Twenty: %d\n" ,value);
printf("Ten: %d\n" ,value);
printf("Five: %d\n" ,value);
return;
}

int main()
{
int num;
int value;

Getnum(num);
DoCalc((num, value));
PrintCal(value);

return(0);
}```
and the second compiles but when you enter a number it prints an infinite loop
Code:
```include<stdio.h>

void Getnum1(int &num1)
{
printf("Please enter a number between 5 and 95 in cents\n");
scanf("%d%*c", &num1);
}

void DoCalc(int num1)
{
int fifty = 0;
int twenty = 0;
int ten = 0;
int five = 0;

while(num1 > 0 && num1 >= 50)
{
num1 = num1 - 50;
fifty++;
printf("Fifty: %d\n" ,fifty);
}

while(num1 > 0 && num1 >= 20)
{
num1 = num1 - 20;
twenty++;
printf("Twenty: %d\n" ,twenty);
}

while(num1 > 0 && num1 >= 10)
{
num1 = num1 - 10;
ten++;
printf("Ten: %d\n" ,ten);
}

while(num1 > 0 && num1 >= 5)
{
num1 = num1 - 50;
five++;
printf("Five: %d\n" ,five);
}
return;
}

int main()
{
int num1;

Getnum1(num1);
DoCalc(num1);

return(0);
}```
please can you help me in anyway to fix both.

2. So what are the compiler errors of the first?

This condition (and its siblings) doesn't make sense:
num1 > 0 && num1 >= 50
If num1 is greater than or equal to 50, the first part is a given.

I don't see anything that would cause an infinite loop. But I do see that you subtract 50 in the 5 clause.

3. is that it thank you very much!!! I feel like such an idiot right now!
anyway the errors in the first are

warning line 34: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 28: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 22: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 16: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 11: 'value' is assigned a value that is never used in function DoCalc(int &,int)
error line 54: call of nonfunction in function main()

i sort of understand what they mean but dont know how to fix them especially the one in the main function have tried everything.

4. >> DoCalc((num, value));
Remove the extra parentheses.

5. Thank you,

but it still says value is assigned but never used how would i make it apart of the code?

And thanks again for all your help.

6. Originally Posted by lil_rom
Thank you,

but it still says value is assigned but never used how would i make it apart of the code?

And thanks again for all your help.
int &value (just like int &num).