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
Using more than one array to store related data is called _____________ arrays.
Makovka662 [10]
It is called matrix arrays
6 0
3 years ago
Read 2 more answers
Which of these might be an example of an advertisers target group
Eduardwww [97]
Where are the examples?

3 0
3 years ago
What are some of the challenges that could arise from setting up a file management system on a computer?
kherson [118]
YOU COULD POTTENTIALLY HAVE TO WIPE ALL CURRENT FILES CLEAN OR U MAY HAVE TO PAY FOR CERTAIN PROGRAMS
7 0
4 years ago
What is the bleed space in a design?
pav-90 [236]

Answer:

The bleed is the part on the side of a document that gives the printer a small amount of space to account for movement of the paper, and design inconsistencies. Artwork and background colors often extend into the bleed area. After trimming, the bleed ensures that no unprinted edges occur in the final trimmed document.

Explanation:

8 0
3 years ago
FIRST PERSON TO FINISH GETS BRAINLIST
ivanzaharov [21]
1. D

2. D

3. ?

4. False

5. True

3 0
3 years ago
Other questions:
  • A circuit contains two 500 OHM resistors connected in parallel and is supplied with 60 VDC. What is the current in the circuit?
    12·2 answers
  • To add and remove chart elements, you can use the add chart element button in the charts layout group on the ____ tab.
    6·1 answer
  • Sarah is working on a project in which she needs to record all the extracurricular activities in her college. Her college teache
    5·1 answer
  • Which architecture for deploying a firewall is most commonly used in businesses today? Why?
    15·1 answer
  • All health information available on the internet is valid. <br> a. true <br> b. false
    6·1 answer
  • What is the second stage of information processing cycle​
    10·2 answers
  • Describe how to add slide numbers and image to a Microsoft power point presentations ?​
    5·1 answer
  • Explain different types of networking-based attacks
    5·1 answer
  • when I turn on my pc using a graphics card, it does give video, and everything is normal, but when I try to turn on my pc with t
    8·1 answer
  • In cell N2, enter a formula using the IF function and structured references as follows to determine which work tier Kay Colbert
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!