// 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 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.
#include <iostream>
using namespace std;
int main()
{
string name;
char exitOut;
bool flag = true;
do
{
cout << "Please enter your name: ";
cin >> name;
cout << "The name you entered is " << name << endl;
cout << "Would you like to exit program?(write down Y or N)" << endl;
cin >> exitOut;
if(exitOut == 'Y')
{
flag = false;
}
}
while(flag);
return 0;
}
In case of using do-while loop, at least one time it will be executed(because it executes before checking the the condition
Comments
Leave a comment