in C Create a do while loop. Inside the loop intake an age as an integer. If the age is less than 21 then the loop should repeat until an age over 21 is inputted.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in C

Create a do while loop. Inside the loop intake an age as an integer. If the age is less than
21 then the loop should repeat until an age over 21 is inputted.

Expert Solution
Step 1: Algorithm:

The algorithm for the C program uses a do-while loop to continuously prompt the user for their age until they enter an age greater than or equal to 21:

  • Initialize Variables:
    • Declare an integer variable age to store the user's input.
  • Do-While Loop:
    • Start a do-while loop that will execute the following steps at least once:
    1. Prompt for Age:
      • Display a message asking the user to enter their age.
    2. Read User Input:
      • Read the user input as an integer and store it in the age variable.
    3. Check Age:
      • Check if the value of age is less than 21.
    4. Age Validation:
      • If age is less than 21:
        • Display a message informing the user that they must be at least 21 years old to continue.
        • Repeat the loop (go back to step 3).
  • Exit Loop:
    • Once the value of age is greater than or equal to 21, exit the loop.
  • Display Confirmation Message:
    • Display a message thanking the user for entering a valid age.
  • Program End:
    • End the program.


steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education