Answer to Question #307463 in C++ for nickname

Question #307463

Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before.

 

Output:

Enter the full name of a person that can serve as a reference:  [user types: Bob Smith]

Bob Smith is reference #1

Would you like to enter another name (Y or N)?  [user types: y]

Enter the full name of a person that can serve as a reference:  [user types: Maria Garcia]

Maria Garcia is reference #2

Would you like to enter another name (Y or N)?  [user types: N]


You have a total of 2 references


1
Expert's answer
2022-03-07T12:52:27-0500






#include <iostream>
#include <string>
using namespace std;




int main() {
	string fullName;
	string answer;
	int referenceNumber=1;
	do{
		cout<<"Enter the full name of a person that can serve as a reference:  ";
		getline(cin,fullName);
		cout<<fullName<<" is reference #"<<referenceNumber<<"\n";
		referenceNumber++;
		cout<<"Would you like to enter another name (Y or N)? ";
		getline(cin,answer);
	}while(answer.compare("y")==0 || answer.compare("Y")==0);
	referenceNumber--;
	cout<<"You have a total of "<<referenceNumber<<" references\n";
	system("pause");


	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