Google Answers Logo
View Question
Q: C++ References for Mad-Libs program ( No Answer,   0 Comments )
Subject: C++ References for Mad-Libs program
Category: Computers > Programming
Asked by: deathpiano-ga
List Price: $5.00
Posted: 27 Jul 2006 16:38 PDT
Expires: 27 Jul 2006 17:37 PDT
Question ID: 750224
How would you improve this MadLibs C++ program by using references?

#include <iostream>
#include <string>

using namespace std;

string askText(string prompt);
int askNumber(string prompt);
void tellStory(string name, string noun, int number, string bodyPart, string verb);

int main()
    cout << "Welcome to Mad Libs.\n\n";
    cout << "Answer the questions and create a story!\n";
    string name = askText("Enter a name: ");
    string noun = askText("Enter a plural noun: ");
    int number = askNumber("Enter a number: ");
    string bodyPart = askText("Enter a body part: ");
    string verb = askText("Enter a verb: ");
    tellStory(name, noun, number, bodyPart, verb);

    return 0;

string askText(string prompt)
    string text;
    cout << prompt;
    cin >> text;
    return text;

int askNumber(string prompt)
    int num;
    cout << prompt;
    cin >> num;
    return num;

void tellStory(string name, string noun, int number, string bodyPart, string verb)
    cout << "\nHere's your story:\n";
    cout << "The famous explorer ";
    cout << name;
    cout << " had nearly given up a life-long quest to find\n";
    cout << "The Lost City of ";
    cout << noun;
    cout << " when one day, the ";
    cout << noun;
    cout << " found the explorer.\n";
    cout << "Surrounded by ";
    cout << number;
    cout << " " << noun;
    cout << ", a tear came to ";
    cout << name << "'s ";
    cout << bodyPart << ".\n";
    cout << "After all this time, the quest was finally over. ";
    cout << "And then, the ";
    cout << noun << "\n";
    cout << "promptly devoured ";
    cout << name << ". ";
    cout << "The moral of the story? Be careful what you ";
    cout << verb;
    cout << " for.";
There is no answer at this time.

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy