Answer to Question #181622 in C++ for Mridul

Question #181622

// 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. 


1
Expert's answer
2021-04-15T16:38:41-0400

//for user friendly we can enter strings of letter this shows program taking sequence of characters and //showing every letter seperately.

#include<iostream>


using namespace std; 


int main() 



string letter = "A"; 


while (letter != "x") 


{ cout << "Please enter a letter" << endl;

 cin >> letter; 


cout << "The letter you entered is " << letter << endl; 



return 0;


//Using do-while loop

#include<iostream>


using namespace std; 


int main() 



string letter = "A"; 

do{

     cout << "Please enter a letter" << endl;

 cin >> letter; 


cout << "The letter you entered is " << letter << endl; 


}


while (letter != "x") ;



return 0;



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS