Assignment2A: Finding multiples We've learned that in programming, there is a special operator for getting the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Assignment2A: Finding multiples We've learned that in programming, there is a special operator for getting the whole number remainder of division: The Modulo Operator! So, 11 % 10 will give us a value of 1, since 10 goes evenly into 11 with a remainder of 1. There are many uses for this operator which we will learn throughout the semester. In this assignment, we're going to use it to find the nearest multiple of a number based on user input. For example, if we're looking for multiples of 6, then the nearest multiple from 13 is 12, and the nearest multiple from 22 is 18 (rounded down). Your task is to: a) Ask the user to enter a whole number they want to find a multiple of b) Read that value in c) Ask the user to enter a second number d) Read that value in e) Use the Modulo Operator to find the nearest multiple of the first number from the second number f) Display the result to the user The algorithm's output is as shown below, with user input in bold. Save your source code in a file called Assignment2A (with a file extension of .cpp, .cs or .java) Sample Output #1: Enter a number you want to find a multiple of: 3 Enter a second number: 10 Calculating... The nearest multiple of 3 from 10 is 9! Sample Output #2: Enter a number you want to find a multiple of: 12 Enter a second number: 95 Calculating... The nearest multiple of 12 from 95 is 84! Sample Output #3: Enter a number you want to find a multiple of: 7 Enter a second number: 33 Calculating... The nearest multiple of 7 from 33 is 28! Assignment2A: Finding multiples We've learned that in programming, there is a special operator for getting the whole number remainder of division: The Modulo Operator! So, 11 % 10 will give us a value of 1, since 10 goes evenly into 11 with a remainder of 1. There are many uses for this operator which we will learn throughout the semester. In this assignment, we're going to use it to find the nearest multiple of a number based on user input. For example, if we're looking for multiples of 6, then the nearest multiple from 13 is 12, and the nearest multiple from 22 is 18 (rounded down). Your task is to: a) Ask the user to enter a whole number they want to find a multiple of b) Read that value in c) Ask the user to enter a second number d) Read that value in e) Use the Modulo Operator to find the nearest multiple of the first number from the second number f) Display the result to the user The algorithm's output is as shown below, with user input in bold. Save your source code in a file called Assignment2A (with a file extension of .cpp, .cs or .java) Sample Output #1: Enter a number you want to find a multiple of: 3 Enter a second number: 10 Calculating... The nearest multiple of 3 from 10 is 9! Sample Output #2: Enter a number you want to find a multiple of: 12 Enter a second number: 95 Calculating... The nearest multiple of 12 from 95 is 84! Sample Output #3: Enter a number you want to find a multiple of: 7 Enter a second number: 33 Calculating... The nearest multiple of 7 from 33 is 28!
Expert Answer:
Answer rating: 100% (QA)
To accomplish this task you can use the following C code include int main Ste... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
what is resourced based view in public administration and why is it important?
-
Basis Furniture Ltd. uses a perpetual inventory system and has a beginning inventory, as at June 1, of 500 bookcases at a cost of $125 each. During June, the company had the following purchases and...
-
Write the names of the people on the list below on a piece of paper in column one of a Word document. Using that list, search the internet and determine or discover what one (or maybe two)...
-
Explain the primary activities of the (a) timekeeping and (b) payroll departments.
-
Danner Company expects to have a cash balance of $46,000 on January 1, 2012. Relevant monthly budget data for the first 2 months of 2012 are as follows. Collections from customers: January $85,000,...
-
At standard temp and pressure (which is sea level pressure of about 1 atm and 25C) we can assume the following relationship-24,000 mL of gas = 1 mole of gas molecules. In fermentation, we can also...
-
1. Tesla uses lease accounting for automotive sales under its resale value guarantee program. Assume that instead of using lease accounting for automotive sales under its resale value guarantee...
-
The tower crane shown is supporting a hook load, P, of 30 kN. The tower (vertical part) is uniform and weighs 40 kN, the boom (horizontal part) is also uniform and weighs 30 kN, and the...
-
Fill in the blanks: ___________________ is used to call a constructor in the parent class, while ___________________ is used to reference a member of the parent class. A. super and this() B. super...
-
What is the output of the following application? A. 8 B. Line p1 contains a compiler error. C. Line p2 contains a compiler error. D. Another line of code contains a compiler error. E. None of the...
-
What can fill in the blank so the play() method can be called from all classes in the com. mammal and com.mammal.eland package, but not the com.mammal.gopher package? package com.mammal; public class...
-
How many lines will not compile? A. Zero B. One C. Two D. Three E. Four F. Five 12: public void print Varargs (String... names) { System.out.println (Arrays.toString (names)); 13: 14: } 15: public...
-
What is the output of the following application? A. TALL B. The code does not compile because of line w1. C. The code does not compile because of line w2. D. The code does not compile for another...
-
Prove that for a polymer solution in the athermal limit (H m = 0), no phase separation can occur in the Flory-Huggins model.
-
Activator rod AB exerts on crank BCD a force P directed along line AB. Knowing that P must have a 100-N component perpendicular to arm BC of the crank, determine (a) The magnitude of the force P, (b)...
-
Suppose a factory located next to a river discharges pollution that causes $2 million worth of environmental damage to the residents downstream. The factory could completely eliminate the pollution...
-
Consider a perfectly competitive market in which the market demand curve is given by Qd = 20 2Pd and the market supply curve is given by Qs = 2Ps. a) Find the equilibrium price and quantity in the...
-
You might think that when a production function has a diminishing marginal rate of technical substitution of labor for capital, it cannot have increasing marginal products of capital and labor. Show...
-
In one area along the interstate, the number of dropped wireless phone connections per call follows a Poisson distribution. From four calls, the number of dropped connections is...
-
The daily number of accidental disconnects with a server follows a Poisson distribution. On five days \[\begin{array}{lllll}2 & 5 & 3 & 3 & 7\end{array}\] accidental disconnects are observed. (a)...
-
Refer to Exercise 7.12. (a) Obtain the maximum likelihood estimates of \(\mu\) and \(\sigma\). (b) Find the maximum likelihood of the probability that the next run will have a production greater than...
Study smarter with the SolutionInn App