L E S S O N S E T 5 Loops and Files Working with the while Loop Bring in program while.cpp from the Lab 5 folder. (This is Sample Program 5.2 from the Pre-lab Reading Assignment). The code is shown below: // PLACE YOUR NAME HERE #include using namespace std; int main() { char letter = 'a'; while (letter != 'x') { cout << "Please enter a letter" << endl; cin >> letter; cout << "The letter you entered is " << letter << endl; } return 0; } Exercise 1: This program is not user friendly. Run it a few times and explain why. Exercise 2: Add to the code so that the program is more user friendly. Exercise 3: How would this code affect the execution of the program if the while loop is replaced by a do-while loop? Try it and see.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 30SA
icon
Related questions
Question

L E S S O N S E T
5 Loops and Files

Working with the while Loop
Bring in program while.cpp from the Lab 5 folder. (This is Sample Program 5.2
from the Pre-lab Reading Assignment). The code is shown below:
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
int main()
{
char letter = 'a';
while (letter != 'x')
{
cout << "Please enter a letter" << endl;
cin >> letter;
cout << "The letter you entered is " << letter << endl;
}
return 0;
}

Exercise 1: This program is not user friendly. Run it a few times and explain
why.
Exercise 2: Add to the code so that the program is more user friendly.
Exercise 3: How would this code affect the execution of the program if the
while loop is replaced by a do-while loop? Try it and see.

Expert Solution
steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
File Input and Output Operations
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage