Question

In: Computer Science

Write a program that accept an integer input from the user and display the least number...

Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s.

Test your solution using this samples]

a. Input: 250

Output: 1x200s, 1x50s

b. Input: 1127

Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s

c. Input: 1127

Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s

d. Input: 19

Output: 1x10s, 1x5s, 4x1s

​[Hints]

o Use division to determine the number of occurrence of each element (i.e. 200, 100) in the input (e.g. Given 500 if we divide it by the largest number possible; which is 200; we will get 2. Therefore, there are 2x200s.)

o Use subtraction to determine the remaining value of the input. (e.g. In the 500 example, since there are 2x200s, we still have 100 to process. The 100 came from 500 – (2*200) = 100.)

o Use the next largest number possible (i.e. 100) to check the number of occurrence. Continue until the remaining value of the input is zero.

Solutions

Expert Solution

#include <iostream>
using namespace std;

int main() {
  
   int number,n1,n2,n3,n4,n5,n6,n7;
   cin>>number;
  
   while(number != 0)
   {
       n1 = number / 200;
       if(n1 != 0)
       {
       cout<<n1<<"*200s,";
       number = number % 200;
       }
       n2 = number / 100;
       if(n2 != 0)
       {
       cout<<n2<<"*100s,";
       number = number % 100;
       }
       n3 = number / 50;
       if(n3 != 0)
       {
       cout<<n3<<"*50s,";
       number = number % 50;
       }
       n4 = number / 20;
       if(n4 != 0)
       {
       cout<<n4<<"*20s,";
       number = number % 20;
       }
       n5 = number / 10;
       if(n5 != 0)
       {
       cout<<n5<<"*10s,";
       number = number % 10;
       }
       n6 = number / 5;
       if(n6 != 0)
       {
       cout<<n6<<"*5s,";
       number = number % 5;
       }
       n7 = number / 1;
       if(n7 != 0)
       {
       cout<<n7<<"*1s";
       number = number % 1;
       }
   }
   return 0;
}

Output:

1127
5*200s,1*100s,1*20s,1*5s,2*1s

Do ask if any doubt. Please upvote.


Related Solutions

Using Matlab do the following Write a program that will accept a number from the user...
Using Matlab do the following Write a program that will accept a number from the user and: Check if the number between 50 and 100both inclusive. If yes print a comment. If not print a warning. The program sums the inserted values This process continues until the user inserts the number 999 . At this point the program quits and prints the result of (2)
JAVA Write a program that will accept user input for an initial deposit and a total...
JAVA Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal. For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%.
Write a program that will accept user input for an initial deposit and a total amount...
Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal. For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%.
Write a program that will accept user input for an initial deposit and a total amount...
Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal. For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%. Then modify it by allowing the user to set a fixed amount to be deposited into...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream> and switch and if-else statements only. Thank you. Ex. Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four Enter a number: 100000 One Hundred Thousand Enter a number: -2 Number should be from 0-1000000 only
Create a C++ program that will prompt the user to input an positive integer number and...
Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT