Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Statement We all know how these magical devices work. People sit inside

ID: 648831 • Letter: P

Question

Problem Statement

We all know how these magical devices work. People sit inside and count out your money and push it through the slot.

You need a job pretty bad and they are hiring! To test your skills they are going to give you a set of coins and a money amount, V, that they want. Your job is to find out the least amount of coins you can give them.

Your input is given as:
Q = number of quarters
D = number of dimes
N = number of nickels
P = number of pennies
V = target amount

Promise
V<100

Input Format

Q D N P V

Output Format

Minimum number of coins.

If you can't make change for the given number, output NO.

Sample Input

2 3 2 1 31

Sample Output

3

Explanation

You can give 31 cents in 3 coins. 1 quarter, 1 nickel, and 1 penny

Explanation / Answer

#include <stdio.h>
#include <conio.h>
void countcoins(int, int, int, int, int);
main()
{
   int q,d,n,p,v;
   printf("Give the number of coins and value in format Q D N P V: ");
   scanf("%d %d %d %d %d", &q,&d,&n,&p,&v);
   countcoins(q,d,n,p,v);
   getch();
  
}

void countcoins(int q, int d, int n, int p, int v)
{
   int qc=0,dc=0,nc=0,pc=0, flag=0;
   int r=0, w=v;
   while(w!=0)
   {
       if(w>24)
       {
           if(q==0)
           {goto dime;}
           else
           {
          
           r=r+25;
           q--;
           qc++;
           w=w-25;
          
          
           }
       }
      
       else if(w>9)
       {
           dime:
           if(d==0)
           {goto nickle;}
           else
           {
          
           r=r+10;
           d--;
           dc++;
           w=w-10;
          
          
           }
       }
       else if(w>4)
       {
           nickle:
           if(d==0)
           {goto penny;}
           else{
          
           r=r+5;
           n--;
           nc++;
           w=w-5;
          
          
       }
       }
       else if (w>0)
       {
           penny:
                      
           r=r+1;
           p--;
           pc++;
           w=w-1;
          
                      
       }
      
              
   }
   if(r==v)
   {
       printf("Number of Coins are as follows: Quater: %d Dime: %d Nickle: %d Penny: %d ", qc,dc,nc,pc);
       printf("Total number of coins: %d",qc+dc+nc+pc);
   }
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote