1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BigorU [14]
3 years ago
11

Write a program name Dollars that calculates and displays the conversion of an entered number of dollars into currency denominat

ions---20s, 10s, 5s, and 1s.
Computers and Technology
1 answer:
Cloud [144]3 years ago
7 0

Answer:

I will code in Javascript.

Preconditions:

  • The variable dollar is passed by parameter to the function.

function Dollars(dollar) {

 

//declare and initialize the variables.

 var twenties = 0;

 var tens = 0;

 var fives = 0;

 var ones = 0;

 

<em>//If dollar is greater or equals 20, divide dollar by 20 and save it into the variable twenties. Then, save the remainder into the variable dollar.  </em>

 if(dollar >= 20){

   twenties = Math.floor(dollar/20);

   dollar = dollar % 20;

 }

<em>//If dollar is greater or equal 10, divide dollar by 10 and save it into the variable twenties. Then, save the remainder into the variable dollar.  </em>

 if(dollar>=10){

   tens = Math.floor(dollar/10);

   dollar = dollar % 10;

 }

<em>//If dollar is greater or equal 5, divide dollar by 5 and save it into the variable twenties. Then, save the remainder into the variable dollar.  </em>

 if(dollar>=5){

   fives = Math.floor(dollar/5);

   dollar = dollar % 5;

 }

<em> //If dollar is greater or equal 1, divide dollar by 1 and save it into the variable twenties. Then, save the remainder into the variable dollar.   </em>

 if(dollar>=1){

   ones = Math.floor(dollar/1);

   dollar = dollar % 1;

 }

//At this point, dollar is equal 0.It's time to display the conversion.

Console.log('20s :' + twenties);

Console.log('10s :' + tens);

Console.log('5s :' + fives);

Console.log('1s :' + ones);

}

Explanation:

The variable Math.floor(num) is used to round a number downward to its nearest integer.

For example, if dollar=57:

twenties = dollar/20 will be 57/20 = 2

dollar = dollar % 20 will be 57 % 20 = 17

tens = dollar/10 will be 17/10 = 1

dollar = dollar % 10 will be 17 % 10 = 7

fives = dollar/5 will be 7/5 = 1

dollar = dollar % 5 will be 7 % 5 = 2

ones = dollar/1 will be 2/1 = 2

dollar = dollar % 1 will be 0 % 5 = 0

You might be interested in
Explain the look of a document which contains several different font sizes and font colors​
Firlakuza [10]

Answer:

Colorful and dynamic?

Explanation:

8 0
3 years ago
Write a program to test the various operations of the class clockType
Umnica [9.8K]
The class clock type was designed to implement the time of day in a program. Certain applications, and additions to hours, minutes, and seconds, might require you to start at the time zone.
5 0
3 years ago
Whatis NOT a key factor while designing a website?
Vaselesa [24]

Answer: Complexity

Explanation: Web designing is referred as the designing of a web page for different purposes such as online business,etc. The most important factor is usability for the improvement in performance of any site and keeping it successful.

It should be user friendly so that interaction and understanding between user and web page can easy.Consistency is also a feature which ensure that web page opened in any browser should have similar quick working.

But there should be no complexity present in the web design which can cause misunderstand with the user and functioning.

7 0
3 years ago
If a user wants to add an expansion card to increase the memory of a computer, where should the user insert the card?
uysha [10]

into a port on the outside of the computer


6 0
3 years ago
Read 2 more answers
What is the name of the User-defined function that is mentioned in the code?
Marizza181 [45]

The name of the user defined function is: footballMatch

6 0
3 years ago
Other questions:
  • A friend was just promoted to a new job that requires part-time travel, and he has also been promised a new laptop after his fir
    10·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an <br> ___?
    14·1 answer
  • - What are the different types of clients?
    12·1 answer
  • Supp guees how your dayyyyyyyyyyyy
    10·2 answers
  • What are the benefits of building redundancy into a network?
    12·1 answer
  • Once the CPU has fetched the data requested, what are the next steps in the process?
    15·1 answer
  • Not every organization integrates with the Internet, but all use some or most of the technology that gave rise to it.
    15·1 answer
  • In what situations might you need to use a function that calls another function?
    11·1 answer
  • How did transistors revolutionize the world of computers?
    15·1 answer
  • Web résumés allow you to include extra graphics and images that you would not include in a traditional résumé. please select the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!