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
During early recording, microphones picked up sound waves and turned them into electrical signals that carved a _______ into the
Tcecarenko [31]

Answer:

Groove

Explanation:

There is not much to explain

8 0
3 years ago
ROE: what does this represent (in plain terms)? In what range would this number typically be? What type of person/position would
LuckyWell [14K]

Answer:

<em>The ROE in plain terms is called  the return on equity (ROE) is a measure of inflow of profit in business in relation to the equity, also known as assets net worth  or assets of liabilities  ROE is a method  of how l  company generate earnings through investment </em>

Explanation:

<em>The ROE in plain terms is called  the return on equity (ROE) is a measure of inflow of profit in business in relation to the equity, also known as assets net worth  or assets of liabilities  ROE is a method  of how l  company generate earnings through investment </em>

<em>The ROE range number can be of any value or percentage example 15% upwards</em>

<em>The type of person or position with roles to play are usually a professional, such as an accountant, bookkeeper, or payroll processor, who completes ROEs on behalf of your clients in the organisation.</em>

4 0
3 years ago
When creating a query using the query design command, first you must ____?
Doss [256]

You must first locate the queries group on the create tab. This tab contains the commands used to create queries. MS Access will switch itself to the query design view. A show table dialog box will appear and you will be able to select a table you would want to run a query on.






5 0
3 years ago
Write the definition of a void function that takes as input an integer and outputs two times the number if it is even; otherwise
KatRina [158]

Answer:

Written in C++

void number(int n){

if(n%2 == 0)

cout<<2 * n;

else

cout<<5 * n;

}

Explanation:

The programming language is not stated.

However, I answered using C++

This line defines the function as void

void number(int n){

This line checks if the number is even

if(n%2 == 0)

If yes, it doubles the number and prints the output

cout<<2 * n;

If otherwise,

else

It multiplies the number by 5 and prints the output

cout<<5 * n;

}

To call the function from main, use:

number(n);

Note than n must be declared as integer

See attachment

Download cpp
6 0
3 years ago
C++ a. Write a program that uses the function isPalindrome given in example 6-6 (Palindrome). Test your program on the followinn
Whitepunk [10]

Answer:

#include <iostream>

#include <array>

using namespace std;

bool isPalindrome(string str)  

{  

int length = str.length();  

for (int i = 0; i < length / 2; i++)  

 if (toupper(str[i]) != toupper(str[length - 1 - i]))

  return false;  

return true;  

}

int main()

{

array<string, 6> tests = { "madam", "abba", "22", "67876", "444244", "trymEuemYRT" };

for (auto test : tests) {

 cout << test << " is " << (isPalindrome(test) ? "" : "NOT ") << "a palindrome.\n";

}

}

Explanation:

The toupper() addition forces characters to uppercase, thereby making the comparison case insensitive.

5 0
3 years ago
Other questions:
  • Rachel uses a word processor to write short stories. However, most of her time is spent toying with the keys, rather than in wri
    13·2 answers
  • When do images or graphics in Microsoft Word hurt the document rather than help
    9·1 answer
  • Which of these planets has the coldest surface temperature?
    6·2 answers
  • Infrared, a wireless connection used in the past prior to bluetooth, was limited because it ________.
    10·1 answer
  • Explain how inflation flattens the universe
    6·2 answers
  • The level of competition is an important factor for many people when selecting a physical activity.
    7·2 answers
  • 3. Assume a disk drive from the late 1990s is configured as follows. The total storage is approximately 675MB divided among 15 s
    11·1 answer
  • Josh's boss asked him to write a letter to their customers explaining some upcoming price increases. But Josh was in a hurry to
    8·2 answers
  • The goal of a system is to
    6·1 answer
  • what are the main technologies that have contributed to be growth and commercialization of the Internet
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!