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
loris [4]
3 years ago
5

Tiffany is writing a program to help manage a bake sale. She writes the following code which prompts the user to enter the total

number of items a person is buying and then a loop repeatedly prompts for the cost of each item. She wrote the code but there is a problem: it runs in an infinite loop. How can Tiffany change her code so it doesn't loop forever?line 0 -- var numItems = promptNum("How many items?");line 1-- var total = 0;line 2-- while (numItems > 0){line 3-- total = total + promptNum("Enter next item price");line4-- }line 5-- console.log("The total is" + total);A) Change Line 1 to:var total = -1;B) Change Line 2 to:while (itemsInCart >= 0){C) Change Line 3 to:total = promptNum("Enter next item price");D) Add after line 3:numItems = numItems - 1;E) Add after line 4:numItems = 0;
Computers and Technology
1 answer:
Katyanochek1 [597]3 years ago
8 0

Answer:

Option D is the correct answer for the above question.

Explanation:

  • The above question code executes the infinite while loop because there is no operation in the loop body which helps the loop condition to be false in any iteration of the while loop.
  • Every while loop contains the three thinks, one is starting value for the loop, the second is a condition which states that the body of the loop will execute or not and the third is an operation which states the condition variable to be false or true.
  • The above program has only two think the starting value which is given by the user in numItems variables and the condition check which decides that the value entered should be greater than 0.
  • So to states, the condition will false there needs some increment operation which states the condition variable will be false. So there must be an operation for "numItems" variables because it participates in the condition of the while loop.
  • The operation relates to the "numItems" variable is given only in option D. Hence D is the correct option while the other is not because others do not hold the operation for "numItems" variables.
You might be interested in
(50 POINTS)Look at the code in the example below, and then answer the question.
Artist 52 [7]
Yeah what that guy said tool tip
5 0
3 years ago
Read 2 more answers
To create an instance of Big Decimal for 454.45, use ________.
agasfer [191]

Answer:

C.

Explanation:

Based on the Java documentation; when creating an instance of BigDecimal, we can pass a string as a constructor.

System.out.println(new BigDecimal("454.45"));

8 0
4 years ago
Who has a relationship like this quote?
lora16 [44]

Answer:

me

Explanation:

5 0
3 years ago
Read 2 more answers
Which of the following is not a benefit of aws cloud computing​
Black_prince [1.1K]
Answer: High latency, temporary and disposable resources are not the benefits of AWS cloud computing.

Explanation: AWS is the most reliable and broad platform that offers a wide range of feature services to individuals globally.

Hope this helps (:
4 0
3 years ago
Which of these is an example of open-source software?
AysviL [449]

Answer:

C

Explanation:

8 0
4 years ago
Read 2 more answers
Other questions:
  • 1. Customizable diagrams, including List, Process, and Cycle diagrams, are built into Word and can be found in
    15·2 answers
  • The ____ cell on the worksheet is the one into which you can enter data.â
    15·2 answers
  • Which of the following occurs when the amount of money earned is greater than the
    5·1 answer
  • Find and fix the error in the if-else statement. import java.util.Scanner;
    11·2 answers
  • The Internet Engineering Task Force (IETF) defines the protocols and standards for how the Internet works. The members of the IE
    12·1 answer
  • In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program
    12·2 answers
  • Select the correct answer.
    15·1 answer
  • Which access modifier is not allowed in a struct? Private Public Protected Internal All of the Above None of the Above A block {
    11·1 answer
  • It is considered good practice to save a presentation before printing it. true false
    13·1 answer
  • 2.5 Code: Practice Question 1
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!