Home‎ > ‎Assignments‎ > ‎Hour of Code‎ > ‎Solutions‎ > ‎

Solution to the "Mad Libs" Assignment

Solution to Programming Assignment (see sample output below)

Mad Libs

//Mad Libs Program

//Author: Adina Weisel

#include <iostream>

#include <string>

using namespace std;

void PrintStory(string,string,string,string,string,string,string,string);


int main()

{

string object,bodypart,animal,petname,verb_ing,verb_pt,TypeOfHome,country;

cout<<"We are going to play MADLIBS!!! You know how to play, so let's start!\n\n";

cout<<"Enter an object: ";

cin>> object;

cout<<"\nEnter a bodypart: ";

cin>>bodypart;

cout<<"\nEnter an animal: ";

cin>>animal;

cout<<"\nEnter a name for a pet (only one word): ";

cin>>petname;

cout<<"\nEnter a verb ending in 'ing': ";

cin>>verb_ing;

cout<<"\nEnter a past tense verb: ";

cin>>verb_pt;

cout<<"\nEnter a type of a home (house, apartment, shoe...): ";

cin>>TypeOfHome;

cout<<"\nEnter a name of a country: ";

cin>>country;

cout<<endl<<endl<<"Loading...\n\n";

PrintStory(object,bodypart,animal,petname,verb_ing,verb_pt,TypeOfHome,country);

cout<<endl<<endl<<endl;

return 0;

}


void PrintStory(string object,string bodypart,string animal,string petname,string verb_ing,string verb_pt,string TypeOfHome,string country){

cout<<"This is the story of how I stuck my "<<object<<" in my "<<bodypart<<".\n My pet "<<animal<<", "<<petname<<", was "<<verb_ing<<" me after he had hidden my "<<object<<

".\n This was the best "<<object<<" I'd ever owned! I just had to find it!\n I quickly "<<verb_pt<<" "<<petname<<" and searched for my "<<object<<

".\n I finally found it in my "<< TypeOfHome <<" in "<<country<<" and quickly hid it in my "<<bodypart<<" so that "<<petname<<" wouldn't find it."; 

}


Output:



Comments