Question

In: Computer Science

C++ language code plzzzzz As we know, here're bills with values: 1, 5, 10, 20, 50,...

C++ language code plzzzzz

As we know, here're bills with values: 1, 5, 10, 20, 50, 100. Now, suppose you have enough amount for each kind of bill, when given a price, decide how many bills of each kind you should pay so that the total number of bills is minimized. Output the number of each bill you need to pay in the order 1, 5, 10, 20, 50, 100.

SAMPLE INPUT

77

SAMPLE OUTPUT

2 1 0 1 1 0

---> since two for 1 bill 1 for 5bill 0 for 10 bill 1for 20 bill 1 for 50bill 0 for 100bill(2*1 + 1*5 +0*10 +1*20 + 1*50 + 0*100)

Solutions

Expert Solution

main.cpp:

#include <iostream>
using namespace std;

int main(){
   int amt;
  
   // declare an array of size 6
   // to store bill count for different bill value
   // a[0] for bill value 1
   // a[1] for bill value 5
   // a[2] for bill value 10
   // a[3] for bill value 20
   // a[4] for bill value 50
   // a[5] for bill value 100
   // initialize all array value to 0
   int nb[6] = {0};
   cout<<"Enter total amount: ";
   cin>>amt;
  
   // pay for bill value 1
   if (amt % 5 != 0){
       nb[0] = amt % 5;
       amt = amt - nb[0];
      
   }
  
   // pay for bill value 5
   if (amt % 10 != 0){
       nb[1] = (amt % 10) / 5;
       amt = amt - nb[1] * 5;
   }
  
   // pay for bill value 10 and 20
   if (amt % 50 != 0){
       int temp = amt % 50;
      
       // pay for bill value 10
       if (temp % 20 != 0){
           nb[2] = (temp % 20) / 10;
           temp = temp - nb[1] * 10;
       }
      
       // pay for bill value 20
       nb[3] = temp / 20;
       amt = amt - temp;
   }
  
   // pay for bill value 50
   if (amt % 100 != 0){
       nb[4] = (amt % 100) / 50;
       amt = amt - nb[4] * 50;
   }
  
   // pay for bill value 100
   nb[5] = amt / 100;

   // print array
   for (int i=0; i<6; i++){
       cout<<nb[i]<<" ";
   }
}

Screenshot of code:

Output:

1)

2)


Related Solutions

1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert...
1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert them to Celsius. You convert a Fahrenheit temperature to Celsius by using the following formula: Celsius = 5.0 / 9 * (Fahrenheit - 32). 2.A client has purchased 20 products in a store. Write a C++ code segment to read the unit price and the number of items of each product and to compute and print the total price of all these products.
Question 1 For the dataset: 20, 20, 10, 10, 40, 50, 20, 30, 10, 20, 50,...
Question 1 For the dataset: 20, 20, 10, 10, 40, 50, 20, 30, 10, 20, 50, 60, 20, 30, 50, 20, 30, 40, 30, 30, 30, 50, 40 calculate the max, min, mode, median and mean.(20%) Draw a boxplot with inner and outer fence For the data in part (i), if the value 60 was replaced by 2000, what would you call this value in the dataset? What could be the explanation for such a value? How can you through...
make a calculator in C++ or C language that can take up to 5 values at...
make a calculator in C++ or C language that can take up to 5 values at same time
Expected Return Std. Deviation X 15% 50% M 10% 20% T-bills 5% 0% The correlation coefficient...
Expected Return Std. Deviation X 15% 50% M 10% 20% T-bills 5% 0% The correlation coefficient between X and M is 2 .2 a)     Draw the opportunity set of securities X and M.   b)     Find the optimal risky portfolio ( O ), its expected return, standard deviation, and Sharpe ratio. Compare with the Sharpe ratio of X and M.   c)      Find the slope of the CAL generated by T-bills and portfolio O. d)    Suppose an investor places 2/9 (i.e., 22.22%)...
A box contains forty $1 bills, six $5 bills, three $20 bills, and one $100 bill....
A box contains forty $1 bills, six $5 bills, three $20 bills, and one $100 bill. A bill is randomly selected, let X be the dollar value of the bill. [2a] Construct a probability distribution of X. [2b] Find the expectation of X. [2c] Find the variance and the standard deviation of X.
10? + 50? + 20? + 10? = 100 5? + 15? + 75? − 25?...
10? + 50? + 20? + 10? = 100 5? + 15? + 75? − 25? = 200 25a − 15? − 5? = 300 10? + 20? − 30? + 100? = 400 how to do flowchart using gauss elimination and lu decomposition method
10? + 50? + 20? + 10? = 100 5? + 15? + 75? − 25?...
10? + 50? + 20? + 10? = 100 5? + 15? + 75? − 25? = 200 25a − 15? − 5? = 300 10? + 20? − 30? + 100? = 400 how to write coding in matlab using lu decomposition
Question: An ATM can only dispense bills of the following denominations: $500, $100, $50, $10, $5,...
Question: An ATM can only dispense bills of the following denominations: $500, $100, $50, $10, $5, and $1 When a user withdraws an amount from the ATM, the machine tries to dispense the amount using the least number of bills possible. For instance, if the user requests $1234, the ATM dispenses 2 bills of $500 + 2 bills of $100 + 3 bills of $10 + 4 bills of $1. On the other hand, if the user requests $1235, the...
Question 5 (10 marks) Python Language What is the output of the following code ? (2...
Question 5 Python Language What is the output of the following code ? (2 points) a, b = 0, 1 while b < 10: print b a, b = b, a+b B. Explain List Comprehension (2 points) Given v = [1 3 5] w = [ [2*x, x**2] for x in v] What is the content of w? c. What is tuple ?   What is the difference between tuple and list ? (2 points) D. What is a module ?  ...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT