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
Serggg [28]
2 years ago
12

Write a while loop that prints userNum divided by 4 (integer division) until reaching 2. Follow each number by a space. Example

output for userNum = 160:
40 10 2

Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".

Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Programend never reached." The system doesn't print the test case that caused the reported message.

#include
using namespace std;

int main() {
int userNum;

cin >> userNum;

/* Your solution goes here */

cout << endl;

return 0;
}
Computers and Technology
1 answer:
Slav-nsk [51]2 years ago
4 0

Answer / Explanation:

#include <iostream>  

using namespace std;

int main()  

{    

 int userNum = 0;  

  userNum = 20;    

  cout << userNum << " ";

  while (userNum > 1)    

  {

     userNum = userNum/2;

     cout << userNum << " ";    

  }    

  cout << endl;  

  return 0;  

}

However, we should note that the above codes divides properly but when it gets to 0, it will always give output as 0 instead of terminating the program.

Hence to make it terminate, we include:

while (userNum > 1)    

{

  cout << userNum << " ";    

  userNum = userNum/2;

}    

The above code alternatively should be replaced with int userNum = 0;  .

Also, for the sake of industry best standard and the general principle, we can say:

The general principle is:

while ( <conditional> )

{

  // Use the data

  // Change the data as the last operation in the loop.

}

A for loop provides natural placeholders for these.

for ( <initialize data>; <conditional>; <update data for next iteration> )

{

  // Use the data

}  

If you were to switch to using a for loop, which I recommend, your code would be:

for ( userNum = 20; userNum > 0; userNum /= 2 )

{

  cout << userNum << " ";

You might be interested in
Can anyone help me out with my photography questions?
Oliga [24]
Verifying, The answer above me is correct
6 0
2 years ago
What is the definition of software? Group of answer choices an instruction that causes a single specific action to be performed
zmey [24]

Answer:

The answer is started from the last fourth line i.e., a series of

Explanation:

Software seems to be the set of linked commands which inform the system or smartphone what tasks to do as well as how to execute.

In the simple words, the software is the set of the program that direct the following smartphones and also the systems that how they work and how to perform these works accurately.

So, the following are the reasons that describe the other options that are not appropriate for software.

7 0
3 years ago
A ____ is any key that uniquely identifies each row.
Mrac [35]
<span>A _superkey___ is any key that uniquely identifies each row.</span>
6 0
3 years ago
Does the Main Content (MC) of a web page include searchboxes?
Tanzania [10]
Yes it does use search boxes
8 0
3 years ago
Read 2 more answers
Which of these has an onboard key generator and key storage facility, as well as accelerated symmetric and asymmetric encryption
Darya [45]

Answer:

Hardware security module.

Explanation:

Hardware security module is a Physical digital device that comes as a plug-in adapter used to secure and manage digital keys and provides crypto processing for strong authentication.

It has an onboard cryptographic keyboard and one or more crypto processors, and can be used on computers and network servers to prevent logical or physical authentication access to unauthorized users. It supports symmetric and asymmetric cryptography.

8 0
3 years ago
Other questions:
  • A person who wants to buy a compact disc (cd) has just enough money to buy one, and chooses cd a instead of cd
    10·2 answers
  • How many ways can you add an image into google slides?
    8·1 answer
  • Why is information broken down into packets
    15·1 answer
  • The biggest limitation of a network operating system (NOS) is _____ in terms of memory, process, device, and file management.
    7·1 answer
  • How do u delete a post on brainly
    7·1 answer
  • It is a blueprint of a project​
    9·2 answers
  • Whats 12/29 divided by 12/34
    7·2 answers
  • Vector images take up much less space when saved to a computer or storage device because computers and storage devices just need
    14·2 answers
  • Say true or false
    10·2 answers
  • System development life cycle
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!