Selection Structures and Pseudocode Examples

Selection Structures and Pseudocode Examples
Slide Note
Embed
Share

In this content, you will find examples of selection structures and pseudocode, along with explanations and code snippets. Explore the pseudocode for IF statements, IF-ELSE statements, and more, illustrated with clear examples and images.

  • Selection
  • Pseudocode
  • Examples
  • Programming
  • Logic

Uploaded on Feb 26, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Selection Structures

  2. Pseudocode Pseudocode - - IF IF Statement Statement BEGIN MAIN CREATE Fahrenheit = 0, Celsius = 0 PRINT Enter Celsius temperature: READ user input Celsius = user input Fahrenheit = 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit >= 90) THEN PRINT heat warning ENDIF Ps END MAIN

  3. Example Example - - if if Statement Statement double celsius = 0.0, fahrenheit = 0.0; cout << " What is the Celsius temperature ? "; cin >> celsius; fahrenheit = 9.0 / 5.0 * celsius + 32; cout << "The temperature is " << fahrenheit << " degrees Fahrenheit"; if (fahrenheit >= 90) { cout << "It is really hot out there!"; }

  4. Pseudocode Pseudocode IF IF- -ELSE ELSE Statement Statement BEGIN MAIN CREATE Fahrenheit = 0, Celsius = 0 PRINT Enter Celsius temperature: READ user input Celsius = user input Fahrenheit = 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit >= 90) THEN PRINT heat warning ELSE PRINT there is no extreme heat ENDIF END MAIN Ps

  5. Example Example if if- -else (Code Snippet) (Code Snippet) else double celsius = 0.0, fahrenheit = 0.0; cout << " What is the Celsius temperature ? "; cin >> celsius; fahrenheit = 9.0 / 5.0 * celsius + 32; cout << "The temperature is " << fahrenheit << " degrees Fahrenheit"; if (fahrenheit >= 90) { cout << "It is really hot out there!"; } else { cout << "There is no extreme heat today."; }

  6. Pseudocode Pseudocode IF IF- -ELSE ELSE- -IF IF BEGIN MAIN CREATE Fahrenheit = 0, Celsius = 0 PRINT Enter Celsius temperature: READ user input Celsius = user input Fahrenheit = 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit >= 90) THEN PRINT heat warning ELSE IF (Fahrenheit >= 80) THEN PRINT it is warm, but there is no extreme heat ELSE IF (Fahrenheit >= 70) THEN PRINT the temperature is pleasant and suggest a picnic ELSE PRINT a suggestion to take a jacket END IF END MAIN Ps

  7. Example Example if if- -else else- -if if double celsius = 0.0, fahrenheit = 0.0; cout << " What is the Celsius temperature ? "; cin >> celsius; fahrenheit = 9.0 / 5.0 * celsius + 32; cout << "The temperature is " << fahrenheit << " degrees Fahrenheit"; if (fahrenheit >= 90) { cout << "It is really hot out there!"; } else if (fahrenheit >= 80) { cout << "It is very warm!"; } else if (fahrenheit >= 70) { cout << "It is very pleasant!"; } else { cout << "It is cool today"; }

  8. Pseudocode Pseudocode switch switch Statement Statement // Read user input like before conditions = compute using Fahrenheit variable / 10 PRINTLINE("It is in the " + conditions + "0's.") SWITCH (conditions) CASE 10: PRINT stay inside , BREAK CASE 9 : PRINT be careful due to heat , BREAK CASE 8 : PRINT it is hot, but not extreme , BREAK CASE 7 : PRINT pack a picnic , BREAK DEFAULT : PRINT take a jacket , BREAK ENDCASE Ps

  9. switch switch Example Example int fahrenheit = 90; int conditions = (int)fahrenheit / 10; cout << "It is in the " << conditions << "0's."; switch (conditions) { case 10: break; case 9: cout << "It is really hot out there!"; break; case 8: cout << "It is warm, but no extreme heat!"; break; case 7: cout << "It is very pleasant today!"; break; default: cout << "Take a jacket!"; break; } cout << "It s hot! Stay inside!";

More Related Content