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
Notes and Hints:
1) You MUST use a DO-WHILE LOOP
2) You must accept the upper and lower case versions of Y and N in the user's reply
3) Hint: That function you used in the previous problem with have a small issue here. That is because there is a newline (Enter) in the keyboard buffer after the user types Y or N. Do you remember how we ignored that extra newline in Chp 3?
#include<iostream>
using namespace std;
int main(){
char first[20],last[20],y;
while((y!='y')|| (y!='Y') ){
cout<<"Enter first and last name"<<endl;
cin>>first>>last;
cout<<"type exit to quit"<<endl;
cin>>y;
if((y=='n')||(y=='N')){break;}
}
return 0;}
Comments
Leave a comment