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
Gekata [30.6K]
3 years ago
7

What is output by the following C# code segment?int temp;temp = 180;while ( temp != 80 ) {if ( temp > 90 ) {Console.Write( "T

his porridge is too hot! " );// cool downtemp = temp – ( temp > 150 ? 100 : 20 ); } // end ifelse {if ( temp < 70 ) {Console.Write( "This porridge is too cold! ");// warm uptemp = temp + (temp < 50 ? 30 : 20);} // end if} // end else} // end whileif ( temp == 80 )Console.WriteLine( "This porridge is just right!" );
Computers and Technology
1 answer:
Artemon [7]3 years ago
7 0

Answer:

This porridge is too hot! This porridge is just right!

Explanation:

I am going to explain every line of the given C# code to give explanation of the output.

  • The first statement int temp declares a variable temp.
  • Then the temp variable is assigned a value 180.
  • The block of statement in while loop body will keep executing until the value in temp variable gets equal to 80. The while loop first checks if the value of temp is not equal to 80. As the value of temp=180 which is not equal to 80, this means that the condition of while loop evaluates to true so the block of code in the body of the loop is reached.
  • There is an if condition inside while loop which checks if the value in temp variable is greater than 90. As value of temp=180 which is greater than 90 so the condition is true.
  • As the condition in the if statement evaluates true so the block of code which is the part of this if statement will be executed:

             {Console.Write( "This porridge is too hot! " );

                  temp = temp – ( temp > 150 ? 100 : 20 ); }

  • The first statement is executed which displays this message: This porridge is too hot!
  • Next   temp = temp – ( temp > 150 ? 100 : 20 ); statement will change the value of temp. It has the conditional operator which works as follows:

                 Here, temp>150 is the condition to be evaluated.

  • If this condition is True then 100 will be returned else 20 will be returned. The value returned is then subtracted from the value of temp and the subtraction result will become the new value of temp. As the value of temp which is 180 is greater than 150 so 100 is returned and is subtracted from the value of temp (180).

                                        temp= 180-100

                                             temp=80

  • So the new value of temp is 80.
  • The else part will not be executed because the condition in if statement was true and also we can see that temp is not less than 70. It means that the porridge is too cold part will not be executed.
  • The while loop while(temp!=80) will again be checked. As the new value of temp is now 80, so the condition gets false which breaks the while loop and program control will leave the body of while loop.
  • After the control comes out of the while loop, there is another if statement. This statement checks if the value of temp variable is equal to 80. It is true as the new value of temp is now 80 after that execution of while loop block of code.
  • As the if condition evaluates to true the statement

                    Console.WriteLine( "This porridge is just right!" );

       will be executed which displays the message:

                                  This porridge is just right.

  • Hence the output of the given code is:

           This porridge is too hot! This porridge is just right!

You might be interested in
Select the correct answer from each drop-down menu.
Dmitry_Shevchenko [17]

Answer:

Suzanne needs a blog

Explanation:

Because she wants to use a digital media tool that acts as a journal and facilitates discussion, Suzanne would need a blog for this.

A blog is a platform where people can meet and have discussions on the internet sometimes in a diary-like format.

Suzanne would need software like WordPress for her blog.

8 0
3 years ago
You are a project manager tasked to implement a critical application in a reputed bank. A client review indicates that you could
Basile [38]
A. diligence in service
6 0
2 years ago
Read 2 more answers
A ________ algorithm is a method of locating a specific item of information in a larger collection of data.
pav-90 [236]
A .) Sort

more ... To arrange or group in a special way (such as by size, type or alphabetically).
6 0
3 years ago
A package that includes hardware, software, and support from a single vendor is called a(n ____ package.
dmitriy555 [2]
The appropriate response is turnkey. It is a kind of venture that is built so it can be sold to any purchaser as a finished item. This is stood out from work to request, where the constructor fabricates a thing to the purchaser's correct determinations, or when an inadequate item is sold with the supposition that the purchaser would finish it.
6 0
3 years ago
Your website is currently at position 5 in organic search. On a monthly basis you currently get on average 5,432 clicks and 32 c
Natalka [10]

Answer:

Answered

Explanation:

This one is worth if I can get more number of clicks and the conversions.

SEO plays a vital role in bringing the website ahead of the competition. In the long run, if a website can reach their target audience with the organic search, then it saves a lot spending over the paid campaigns to bring business. Bringing the website to first position will automatically increase the impression which in turn will result in the more clicks and conversions.

7 0
3 years ago
Other questions:
  • The _____ icon looks like a clipboard with a page of paper attached. Cut Copy Paste Clipboard
    5·1 answer
  • Prior to the development of e-commerce, web sites primarily delivered static html pages. true
    11·1 answer
  • Ryan has created a Word document to be used as a review quiz for students in a classroom setting. The document contains both que
    6·1 answer
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • Reading for subject content follows the same steps as reading for entertainment. True or false.
    10·2 answers
  • What makes iron man different from other superheroes ? why is iron man the best superhero ??
    5·2 answers
  • Arrange the steps below to outline what maia needs to do to accomplish this task.​
    9·1 answer
  • Advantages of heading attributes
    5·1 answer
  • How is the internet made?
    7·1 answer
  • PLEASE HELP WILL GIVE BRAINLIEST!!!’
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!