MUST BE IN VISUAL Studio Write a Word Game program that plays a word game with t
ID: 3798092 • Letter: M
Question
MUST BE IN VISUAL Studio
Write a Word Game program that plays a word game with the user. The program should ask the user to enter the following:
· His or her name
· His or her age
· The name of a city
· The name of a college
· A profession
· A type of animal
· A pet’s name
Use the getline(cin, variable) syntax since you will have problems when you ask a user for character input that is more than 1 word such as (Lone Star College). Also pay attention to the discussion on cin.ignore().
After the user has entered these items, the program should display the following story inserting the user’s input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of AGE, NAME went to college at COLLEGE. NAME graduated and sent to work as a PROFESSION. Then, NAME adopted a(an) ANIMAL named PETNAME. They both lived happily ever after
The output should be spaced on lines of output so that it reads as a normal paragraph with number of words in each line evenly spaced. Using the “ ” should allow you to keep each line about the same length.
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
string Name,City,College,Profession,PetName,AnimalType;
int Age;
cout<<"Enter your name";
getline(cin, Name);
cout<<" Enter your age";
cin>>Age;
cin.ignore();
cout<<" Enter the name of a city";
getline(cin, City);
cout<<" Enter the name of a college";
getline(cin, College);
cout<<" Enter a profession";
getline(cin, Profession);
cout<<" Enter a type of animal";
getline(cin, AnimalType);
cout<<" Enter a pet’s name";
getline(cin, PetName);
cout<<" There once was a person named "<<Name<<" who lived in "<<City<<". At the age of "<<Age<<", "<<Name<<" went to college at "<<College<<"."<<Name<<" graduated and sent to work as a "<<Profession<<". Then, "<<Name<<" adopted a(an) "<<AnimalType<<" named "<<PetName<<". They both lived happily ever after";
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.