Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Nothing prints to the command prompt when I run this and I don't know why

0 votes
asked Nov 4, 2019 by BlazingMC (120 points)

#include <stdio.h>

int dispense(int money);

int main(void){

int money;

int bill_50;

int bill_20;

int bill_10;

printf("How much money do you want: ");

scanf("%d\n", &money);

dispense(money);

printf("Number of $50 bills: %d\n", bill_50);

printf("Number of $20 bills: %d\n", bill_20);

printf("Number of $10 bills: %d\n", bill_10);

return 0;

}

int dispense (int money){

int bill_50 = 0;

int bill_20 = 0;

int bill_10 = 0;

while (money > 0){

if(money >= 50){

money -= 50;

bill_50++;

}

if(money >= 20 && money < 50){

money -= 20;

bill_20++;

}

if(money >= 10 && money < 20){

money -= 10;

bill_10++;

}

}

return bill_10;

return bill_20;

return bill_50;

}

3 Answers

0 votes
answered Nov 4, 2019 by kernelknight (140 points)
edited Nov 4, 2019 by Admin
#include <stdio.h>

int dispense (int money);

int bill_50 = 0;

int bill_20 = 0;

int bill_10 = 0;

int change = 0;

int

main (void)

{

  int money;

  printf ("How much money do you want: ");

  scanf ("%d", &money);

  dispense (money);

  printf ("Number of $50 bills: %d\n", bill_50);

  printf ("Number of $20 bills: %d\n", bill_20);

  printf ("Number of $10 bills: %d\n", bill_10);

  printf ("change: %d\n", change);

  return 0;

}

int

dispense (int money)

{

  while (money > 0)

    {

      if (money >= 50)

{

  money -= 50;

  bill_50++;

}

      else if (money >= 20 && money < 50)

{

  money -= 20;

  bill_20++;

}

      else if (money >= 10 && money < 20)

{

  money -= 10;

  bill_10++;

}

      else

{

  change = money;

  money = 0;

}

    }

}

from jesse pinkman
0 votes
answered Nov 14, 2019 by rohan ag (1,310 points)
you need to remove the while loop and you had taken function return type as int but you are not catching anything and simultaneously you cant return 3 values like this  so what you want to do tell me i will try to do
0 votes
answered Nov 16, 2019 by anonymous
Return stops the function from executing anymore. So return bill_10 would return value and go back to main(). Return bill_20 and bill_50 won't be executed.

If your returning values you need to put them into a variable e.g variable_name = dispense(money)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...