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
How to automatically ccleaner smartphone?
denis23 [38]
Ccleaner for Android can be set to automatically run on schedule. But please check have u update it.
<span />
8 0
3 years ago
Cmo se puede añadir amigo ??'
seropon [69]

Answer:ok

Explanation:

5 0
3 years ago
Assume you are given three variables, revenue, expenses, and profit, all of type Money (a structured type with two int fields, d
Andre45 [30]

Answer:

if(revenue.cents - expenses.cents < 0){

profit.dollars = revenue.dollars - expenses.dollars - 1;

profit.cents = 1 - revenue.cents - expenses.cents;

}

else{

profit.dollars = revenue.dollars - expenses.dollars;

profit.cents = revenue.cents - expenses.cents;

}

Explanation:

We know that profit is given as: revenue - expenses from the question.

From the given expression above;

if(revenue.cents - expenses.cents < 0)

then profit.dollar will be revenue.dollars - expenses.dollars - 1; the 1 is to be carry over to the cent part. And the profit.cent will be 1 - revenue.cents - expenses.cents;

else the profit.dollars and the profit.cent is computed directly without needing to carry over:

profit.dollars = revenue.dollars - expenses.dollars;

profit.cents = revenue.cents - expenses.cents;

7 0
3 years ago
Which of the following networks had these two goals: a) allowing scientists to work together on scientific projects; and, b) fun
mrs_skeptik [129]

Answer:

ARPANET

Explanation:

It was the ARPANET sponsored by the US Department of Defense to enable scientists collaborate on research.

5 0
3 years ago
Read 2 more answers
Edhesive assignment 7 calendar
ikadub [295]

Answer:

def leap_year(y):

 if y % 4 == 0:

     return 1

 else:

     return 0

def number_of_days(m,y):

 if m == 2:

     return 28 + leap_year(y)

 elif m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m ==10 or m == 12:

     return 31

 elif m == 4 or m == 6 or m == 9 or m == 11:

     return 30

def days(m,d):

 if m == 1:

     return 0 + d

 if m == 2:

     return 31 + d

 if m == 3:

     return 59 + d

 if m == 4:

     return 90 + d

 if m == 5:

     return 120 + d

 if m == 6:

     return 151 + d

 if m == 7:

     return 181 + d

 if m == 8:

     return 212 + d

 if m == 9:

     return 243 + d

 if m == 10:

     return 273 + d

 if m == 11:

     return 304 + d

 if m == 12:

     return 334 + d

def days_left(d,m,y):

 if days(m,d) <= 60:

     return 365 - days(m,d) + leap_year(y)

 else:

     return 365 - days(m,d)

print("Please enter a date")

day=int(input("Day: "))

month=int(input("Month: "))

year=int(input("Year: "))

choice=int(input("Menu:\n1) Calculate the number of days in the given month.\n2) Calculate the number of days left in the given year.\n"))

if choice == 1:

 print(number_of_days(month, year))

if choice == 2:

 print(days_left(day,month,year))

Explanation:

Hoped this helped

5 0
3 years ago
Other questions:
  • The numbers on the bottom of a typical check represent all of the following EXCEPT?
    12·2 answers
  • Write structured pseudocode to show the following: print “Reorder” when the quantity is less than 20; otherwise print “OK”.
    15·1 answer
  • What was the technology that defined each of the four generations of computers?
    12·1 answer
  • The algorithm and flowchart
    9·1 answer
  • I need some help with this assignment. I'm having difficulty trying come up ideas to use here. Can I get any help?
    5·1 answer
  • A good sentence about art
    9·1 answer
  • How would you describe<br> "analogous color harmony" to a six year old?
    13·1 answer
  • Which of these is NOT an input device?
    14·1 answer
  • _______ is a medium-range wireless network. ________ is a medium-range wireless network. Cellular radio LTE UWB Wi-Fi
    12·1 answer
  • You find a picture of a famous department store online that would be great to include in a project of yours. What should you do
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!