C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 18th, 2004, 09:15 AM
Claricemajor Claricemajor is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: New York
Posts: 2 Claricemajor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Help with a madlib problem

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

Reply With Quote
  #2  
Old November 18th, 2004, 04:12 PM
code_geek code_geek is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 9 code_geek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with a madlib problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT