Given positive integer numInsects, write a while loop that prints that number doubled without reaching 100. Follow each number with a space. After the loop, print a newline. Ex: If numInsects = 8, print:

8 16 32 64

#include

using namespace std;

int main() {

int numInsects = 0;

numInsects = 8; // Must be >= 1

while (numInsects < 100) {

numInsects = numInsects * 2;



cout << numInsects << " ";

}

cout << endl;

return 0;

}

So my question is what am I doing wrong?

Answers

Answer 1

Answer:

The cout<<numInsects<<""; statement should be placed before numInsects = numInsects * 2;  in the while loop.

Explanation:

Your program gives the following output:

16  32  64  128

However it should give the following output:

8  16  32  64

Lets see while loop to check what you did wrong in your program:

The while loop checks if numInsects is less than 100. It is true as numInsects =8 which is less than 100.

So the body of while loop executes. numInsects = numInsects * 2;  statement in the body multiplies the value of numInsects i.e 8 with 2 and then cout << numInsects << " ";  prints the value of numInsects  AFTER the multiplication with 2 is performed. So 8 is not printed in output but instead 16 (the result of 8*2=16) is printed as the result of first iteration.

So lets change the while loop as follows:

while (numInsects < 100) {

cout << numInsects << " ";

numInsects = numInsects * 2;

Now lets see how it works.

The while loop checks if numInsects is less than 100. It is true as numInsects =8 which is less than 100

So the body of while loop executes. cout << numInsects << " "; first prints the value of numInsects i.e. 8. Next numInsects = numInsects * 2;  multiplies the value of numInsects i.e 8 with 2. So first 8 is printed on the output screen. Then the multiplication i.e. 8*2=16 is performed as the result of first iteration. So now value of numInsects becomes 16.

Next the while loop condition numInsects < 100 is again checked. It is true again as 16<100. Now cout << numInsects << " "; is executed which prints 16. After this, the multiplication is again performed and new value of numInsects becomes 32 at second iteration. This is how while loops continues to execute.

So this while loop stops when the value of numInsects exceeds 100.

Given Positive Integer NumInsects, Write A While Loop That Prints That Number Doubled Without Reaching

Related Questions

DEF is a small consulting firm with ten on-site employees and 10 to 12 part-time (off-site) software consultants. Currently, the network consists of 2 servers for internal business processes, 1 server that handles the call-in connections; 10 on-site wireless workstations/devices, and 2 printers. Respond to the following in a minimum of 175 words: Identify one network security strategy that would help this organization. Why did you choose this strategy over others

Answers

Answer:

What i would suggest for the organization is to use the Testing Infrastructure strategy. it is good for your consulting firm because it is less costly and provide security.

Explanation:

Solution

There are different network security strategy which is listed below:

Segment the network:

Segmentation in network is very useful for providing security.If any threat is occur only one segment is effected remaining are safe and it is less cost process. very useful for small organizations.

Test your infrastructure :

Testing infrastructure also very good technique.

Always we have to test our infrastructure whether threat is occur or not.

If any threat is happen we can detect that easily by testing our infrastructure.

Regularly update anti-virus software :

This is very useful for small organizations and it is less cost.with less cost we can provide security for all devices like computer,server,modems etc.

Frequently backup your critical data :

This is very good technique for crucial data.If we backup important data any time that will be useful if any attack is happen.

This is less costs and simple.

Change router default security settings :

Changing router password and settings also helpful for providing security.If we maintain same password and same settings for a long time that may lead to data hacking.It is cost less process very useful for small organizations.

if you want to exclude a portion of an image which option should be chosen?? A. Arrange B. Position C. Crop D. Delete

Answers

It would be C- crop. This allows you to specifically delete parts of the image using drag and drop features. Hope this helps!

If i wanted to change my phones simcard, does anything need transferring, or is it an easy swap?

Answers

Most likely not but I think you’ll have to log in your account like if you have an Apple phone . You’ll have to log into your Apple ID

Describe any five GSM PLMN basic services?

Answers

Answer:

Your answer can be found in the explanation below.

Explanation:

GSM is the abbreviation for Global System for Mobile communication. Its purpose is to transmit voice and data services over a range. It is a digital cellular technology.

PLMN is the abbreviation for Public Land Mobile network. It is defined as the wireless communication service or combination of services rendered by a telecommunication operator.

The plmn consists of technologies that range from Egde to 3G to 4G/LTE.

PLMN consists of different services to its mobile subscribers or users but for the purpose of this question, i will be pointing out just 5 of them alongside its definitions.

1. Emergency calls services to fire or police: Plmn provides us with the option to make emergency calls in the event of any accident or fire incident, etc.It is available on devices either when locked or unlocked.

2. Voice calls to/from other PLMN: This entails the putting of calls across to persons we cannot reach very quickly. PLMN helps to connect persons through its network of from other networks thus making communication easier.

3. Internet connectivity: PLMN provieds us with internet services through wifi or bundles that enable us have access to the internet as well as help us communicate with people and loved ones over a distance. Internet service are possble either on GPRS or 3G or 4G networks.

4. SMS service: SMS means short messaging service. This is also know as text messages. PLMN allows us to be able to send short messages to people as oppposed to mails. It is mostly instant and can be sent or recieved from the same PLMN or others.

5. MMS service: Multimedia messaging service whose short form is MMS ccan be descibed as the exchange of heavier messages such as a picture or music or document but not from an email. It is availabel for use from one PLMN to another.

Cheers.

All of the following are true about hacksaws except: a. A hacksaw only cuts on the forward stroke. b. A coarse hacksaw blade (one with fewer teeth) is better for cutting thick steel than a fine blade. c. A fine hacksaw blade (one with many teeth) is better for cutting sheet metal. d. A hacksaw blade is hardened in the center, so it is best to saw only with the center portion of the blade.

Answers

B is INCORRECT good sir. The Hope this helps, brainiest please.

All of the following are true about hacksaws, except a coarse hacksaw blade (one with fewer teeth) is better for cutting thick steel than a fine blade. The correct option is b.

What is a hacksaw?

A hacksaw is a saw with fine teeth that were originally and primarily used to cut metal. Typically, a bow saw is used to cut wood and is the corresponding saw.

Hacksaw is used by hand, it is a small tool for cutting pipes rods wood etc that is very common and homes and in shops. The different types of hacksaws. The main three types of hacksaws are course-grade hacksaws, medium-grade hacksaws, and fine-grade hacks. The difference is just for the quality, and the design of the blade.

Therefore, the correct option is b. Cutting thick steel is easier with a coarse hacksaw blade (one with fewer teeth) than a fine one.

To learn more about hacksaw, refer to the below link:

https://brainly.com/question/15611752

#SPJ2

Other Questions
How does population density differ from population size?. Population size takes all organisms into account while population density only takes specific agegroups of the population into accountb. Population size is the total number of organisms, while population density is the total number oforganisms within a given areaC Population size is the total number of organisms within a given area, while population density is thetotal number of organisms of a specific aged. Population size is the total number of organisms of all species, while population density is the totalnumber of organisms of a specific species Please help me or assist me in answering this Thank you 5 2/3 X 6 7/8 The Pyrenees mountain range isabout how many feet up inElevation? A man purchased 10 pens. He sold 5 pens at 25% profit and the remaining 5pens at [tex]16 \frac{2}{3} [/tex]% loss. If he received Rs 625 in total, find the cost price of each pen.help!!! An 18-kg bicycle carrying a 62-kg girl is traveling at a speed of 7 m/s. What is the kinetic energy of the girland bicycle combined together? anyone please answer this Solve x/2 + y/3 = 1 for x A grasshopper sits on the first square of a 1N board. He can jump over one or two squares and land on the next square. The grasshopper can jump forward or back but he must stay on the board. Find the least number n such that for any N n the grasshopper can land on each square exactly once. please helppppp bc i dont understand this one Brooke Hubert works for MRK all year and earns a monthly salary of $ 11 comma 900. There is no overtime pay. Brooke's income tax withholding rate is 10 % of gross pay. In addition to payroll taxes, Brooke elects to contribute 5 % monthly to United Way. MRK also deducts $ 125 monthly for co-payment of the health insurance premium. As of September 30, Brooke had $ 107 comma 100 of cumulative earnings. LOADING...(Click the icon to view payroll tax rate information.) Requirements 1. Compute Brooke's net pay for October. 2. Journalize the accrual of salaries expense and the payments related to the employment of Brooke Hubert. trace the history of Meghalaya briefly 80 words minimumly how wood helps in home insulation plz answer fastplz answwweeeeeeerrrrrrr Candy draws a square design with a side length of x inches for the window at the pet shop. She takes the design to the printer and asks for a sign that has an area of 16x2 40x + 25 square inches. A square labeled 16 x squared minus 40 x + 25 What is the side length, in inches, of the pet shop sign? List and describe 3 events or documents that led to the Creation of the Constitution. Leleti believes that her friend spilled soda all over her backpack in order to get revenge for a remark Leleti made a few days ago, even though her friend claims that the incident was an accident. Leleti is making a: to compare the way two different texts present similar ideas. What is the area of the triangle given below? 2 and 6 Complete 9 additional base pairs.Remember there is no thymine (T) in RNA the adenine (A) in the DNA needs to pair with uracil (U) Which term best describes the temperature and weather conditions of an organisms environment? Please answer this correctly