| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have this program that is due on 10/18/2004. I am suppose to write a program to produce a
simple Madlib. My instructions says to write a function that will return a word. The function is sent a string which is a prompt to make it ask for the required part of speech. So the same function can ask: "Please enter a verb" or " Please enter a noun" or anything else you want it to. The word is input by the user and returned by the function. I have to start off my using a program stub, which I know how to do. Second it says to Test the logic of your function call in main. Change main so that is calls the function to collect the user's words for the parts of speech that you identified in your story . Add to main so that it will output the story using the four words chosen by the user and returned by the function. Please help me anyone ![]() |
|
#2
|
|||
|
|||
|
well, this is a month late, but here goes...
well, i don't know what a program stub is, but this code should work (just wrote it fast, untested): #include <iostream> #include <string> #include <cstdlib> string word(string); //string pos (part of speech), 1=n, 2=v, 3=adj, 4=adv int main() { string madlib = "The first word is a noun: " + word(1) + ". The second word is a verb: " + word(2) + ". The third word is an adjective: " + word(3) + ". The fourth word is an adverb: " + word(4) + "."; cout << madlib << endl << endl; system("pause"); return 0; } string word(string pos) { string the_word = "", the_pos = ""; switch(pos) { case 1: the_pos = "noun"; break; case 2: the_pos = "verb"; break; case 3: the_pos = "adjective"; break; case 4: the_pos = "adverb"; break; case default: return "error"; } cout << "Please enter a(n) " + the_pos + ":" << endl; getline(cin, the_word); return the_word; } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Help with a madlib problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|