Is it possible to put a function inside a switch case loop? Because I've tried this just to explore more of this loop. Though I tried other ways but still I've got the problem existed. Can anyone help me?
#include <stdio.h>
int main(void)
{
int choice;
switch(choice);
{
case 1:
{
int GetData()
{
int num;
printf("Enter the amount of change: ");
scanf("%d%*c", &num);
return (num);
}
int getChange (int change,int fifty,int twenty,int ten,int five)
{
int num = change;
fifty = num/50;
num %= 50;
twenty = num/20;
num %= 20;
ten = num/10;
num %= 10;
five = num/5;
num %= 5;
return (fifty, twenty, ten, five);
}
int main()
{
int change, fifty, twenty, ten, five;
change = GetData();
if ((change < 5) || (change > 95) || (change%5 > 0))
{
printf("Amount must be between 5 and 95 and be a multiple
of 5.");
}
else
{
getChange(change, fifty, twenty, ten, five);
printf("Change for %d cents: \n", change);
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(0);
}