My professor likes to give us tests on topics we've not covered yet, like string stream :o

This program uses stringstream objects to make sentences like the Mad Lib ™ game. Create 4 string objects: noun, adjective, verb, and adverb.

You will need these functions: AskNoun, AskVerb, AskAdjective, AskAdverb, and BuildSentence. Call the first four functions to obtain the word values. (You’ll need to pass the user’s noun and verb to the adjective and adverb functions.) Next, pass the four sentence parts into BuildSentence, which creates a complete sentence using these words. Return the sentence to main() to show it to the user. You may make up parts of the sentence if you like. Include a go again loop and goodbye message.

Example of output:

Enter a noun (person, place or thing): table
Enter a verb (an action!): drinks
Enter an adjective (describes the table): large
Enter an adverb (describes how it drinks): sloppily

The large table drinks sloppily.

I know this isnt right but this what i have got:


#include <sstream>
using namespace std;

class Sentence
	void getNoun(string word);
	void getVerb(string word);
	void getAdverb(string word);
	void getAdjective(string word);
	string BuildSentence();
	string Noun;
	string Verb;
	string Adverb;
	string Adjective;


#include <sstream>
#include "SentBuild.h"

void Sentence::getNoun(string word)
	stringstream(word) >> Noun;
void Sentence::getVerb(string word)
	stringstream(word) >> Verb;
void Sentence::getAdverb(string word)
	stringstream(word) >> Adverb;
void Sentence::getAdjective(string word)
	stringstream(word) >> Adjective;
string Sentence::BuildSentence()
	string s = " ";
	string sent = "The "+Adjective+s+Noun+s+Verb+s+Adverb+".\n";
	return sent;


#include <iostream>
#include <sstream>
#include "SentBuild.h"
using namespace std;

void main()
	string ans;

		Sentence sent1;
		string word;

		cout << "Let's play a game of mad lib! \n\n";
		cout << "What is your Noun? ";
		getline(cin, word); sent1.getNoun(word);

		cout << "What is your Verb? ";
		getline(cin, word); sent1.getVerb(word);
		cout << "What is your Adverb? ";
		getline(cin, word); sent1.getAdverb(word);

		cout << "What is your Adjective? ";
		getline (cin, word); sent1.getAdjective(word);

		cout << sent1.BuildSentence() << endl;

		cout << "Do you want to play again? ";
		getline(cin, ans);

		cout << endl;

	} while (ans == "yes" || ans == "Yes");

it works but I do not think this is what he wants.

any suggestions to help me fix this?

7 Years
Discussion Span
Last Post by sfuo

When I think of Mad Libs I think of a preset sentence with blanks in it. You are asked to fill in the blanks with the type of word needed and then you read out the sentence with your words.

For this I would make up like 5 sentences and randomly pick one then ask for user input based on what you need (noun, verb, etc.) and then output the completed sentence with the users input.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.