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

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...
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...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
(8 marks) Write a program to ask user to enter an integer that represents the number...
Write a program to ask user to enter an integer that represents the number of elements, then generate an ArrayList containing elements which are all random integers in range [75, 144] , and finally display index and value of each element. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use ArrayList. Your program must use only printf(…) statements to adjust the alignment of your output. Your code must display the index in descending...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
In Java:Implement a program that repeatedly asks the user to input apositive integer and...
In Java:Implement a program that repeatedly asks the user to input a positive integer and outputs the factorial of that input integer. Do not use recursion, solution should use stack.
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT