1. Help with Modular code!!!!!!!!!!!!!

My code is supposed to give back the correct amount of change in cents(example is give me 25 cents and it prints out 1 twenty cent coin 5 cent) but it keeps coming up with random numbers, need help!!!!

Code:
```#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>

char Displaybanner(Help)
{
int fifty, twenty, ten, five, result;
char option;

printf("\Hello Bank teller.");
do
{
printf("\n\nDo you need help (Y/N)");
option = getch();
option = toupper (option);
}
while (!((option=='Y') || (option=='N')));

printf("%c\n",option);

if (option=='Y')

printf("\nEnter the amount of cents that needs to be returned to the customer: ");
scanf("%d%*c", &result);

return result;

}

int Calculate()

{
int fifty, twenty, ten, five, result;

if ((result<0) || (result>95) || (result%5>0))

fifty = result / 50;
result %= 50;
twenty = result / 20;
result %= 20;
ten = result / 10;
result %= 10;
five = result / 5;
result %= 5;

printf("To make change for the amount you entered, you will need the following coins:\n\n", result);

if (fifty > 1)
printf("%d Fifty cent piece's.\n", fifty);
if (fifty == 1)
printf("%d Fifty cent piece.\n", fifty);
if (twenty > 1)
printf("%d Twenty cent piece's.\n", twenty);
if (twenty == 1)
printf("%d Twenty cent piece.\n", twenty);
if (ten > 1)
printf("%d Ten cent piece's\n", ten);
if (ten == 1)
printf("%d Ten cent piece.\n", ten);
if (five > 1)
printf("%d Five cent piece's\n", five);
if (five == 1)
printf("%d Five cent piece.\n", five);

return result;
}

int main ()
{
int fifty, twenty, ten, five, result;

result = Displaybanner();

Calculate();
}```

2. The variable "result" inside calculate() is not initialised, hence the garbage values.

There is no inherent relationship between result in main(), result in DisplayBanner(), or result in Calculate(). They are all distinct variables, with different addresses in memory, able to hold distinct values, etc etc. They have the same name, but different context or scope (inside their respective functions).

The same goes for other variables.

3. Is this really supposed to be C++? It looks only like C. Did you post in the wrong section?

4. Originally Posted by Elysia
Is this really supposed to be C++? It looks only like C. Did you post in the wrong section?
It's not strictly C either, given the usage of <conio.h> and getch() - neither of which are standard C. But I agree, in terms of library functions used (printf(), scanf()) it is closer to being C than C++.

The scoping concern affecting the OP is the same in both C and C++, so it probably doesn't make much difference what forum it is in.

5. Originally Posted by grumpy
The scoping concern affecting the OP is the same in both C and C++, so it probably doesn't make much difference what forum it is in.
True, but knowing whether it is C or C++ will help us give proper advice. There is more than just scoping issues if it's supposed to be C++, as implied by the forum category.