Need help plz experts or someone

This is a discussion on Need help plz experts or someone within the C++ Programming forums, part of the General Programming Boards category; here is instructions: File Processing Make a Mad Libs party game. The leader has the text of a short story ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    11

    Need help plz experts or someone

    here is instructions:

    File Processing

    Make a Mad Libs party game. The leader has the text of a short story with a few missing words in it. The missing words are tagged by their function [noun], [verb], [place], etc... For example:

    It was a [adjective] summer day.
    Jack was sitting in a [place].

    The leader examines the text and prompts the players for the missing words:

    Please give me a/an:
    adjective
    place
    etc...

    He then reads the text with the supplied words inserted into their places.

    Write a program that acts as the Mad Libs leader. It should prompt the user for a file name (or display a menu of available files), read the text from the chosen file, find the tags for the missing words, prompt the user for the words, and, finally, find the completed text in another file. You MUST use apstring, and, at least 2 funstions. In addition, use the <fstream.h> header file for the class ifstream. You will need to use the open, close, eof, and fail functions.

    The files that i use will include the following: Holdiday, Noun, Verb, Food, Person, Adjective. All words tagged by [ ].






    Code:
    #include<iostream>
    #include<iomanip>
    #include<fstream>
    #include"vector"
    #include"string"
    using namespace std;
    
    
    //Mad Lib
    //Daniel Meade
    
    
    int main()
    {
     ifstream fin;
     ofstream fout;
     string filename, line;
     char temp;
    
    
     do
     {
      fin.clear();
      cout << "What is the file name";
      getline(cin, filename);
      fin.open((filename).c_str());
      if(fin.fail())
       cout << "Not valid file." << endl;
      }while(fin.fail());
    
      while(!fin.eof())
      {
       vector<string>story(19,"");
       vector<string>word(18,"");
    
    
       getline(fin,line);
       if(line.find('[') == 1)
       {
        if(int x=0; x<=18; x++)
         line = word[x];
       }
       else
       {
        if(int y=0; y<=18; y++)
         cout << "enter a word" << word[x] <<":"<< endl;
         cin >> word [x];
       }
       if(int y=0; y<=18; y++)
       {
        cout << story[y];
        if(int x=0; x<=18; x++)
         cout << word[c];
       }
    
      }
      fin.close();
     }
    
     }
    file input

    TWas the night before
    [Holday]
    and all through the
    [Noun],
    not a
    [Noun]
    was
    [Verb]
    ,not even a
    [Noun].
    All the children were tucked all snug in their
    [Noun],
    with visions of
    [Food]
    dancing in their heads.The stockings were hung by the chimney with
    [Verb],
    in hopes that
    [Person]
    soon would be there.I in my kerchief and ma in her
    [Noun],
    had just
    [Verb]
    down for a
    [Adjective]
    winter's nap.When up on the roof on I
    [Verb]
    such a
    [Adjective]
    ,I jumped from my bed to
    [Verb]
    what was the matter.When what do my
    [Adjective]
    eyes do appear,but a
    [Noun]
    and eight
    [Adjective]
    reindeer.

    Errors:

    parse error before ';' token on a bunch of lines what does this mean?
    Last edited by cplusplus12; 02-06-2006 at 07:55 PM.

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Replace your if statements with for.
    Note: There are other errors, post again if you can't sort them out yourself

  3. #3
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    As for your error, like the other guy said if isn't a loop, but for is.. so replace all instances. You probably gonna get some variables not declared and some other stuff.

    if you need an example:

    Code:
    #include<iostream>
    #include<fstream>
    
    using namespace std;
    
    int main()
    {
     ifstream input;
     char word[25];  // Store user inputed word.
    
     input.open("story.txt");  // Open input file.
    
    	input.seekg(0, ios::end);  // Detect length of file.
    
    	int length = input.tellg();  // Store length.
    
    	input.seekg (0, ios::beg);  // Go back to beginning of file.
    
    	char *story = new char[length];  // Create array large enough to hold entire story.
    
    	input.read(story, length);  // Store entire story.
    	
    	input.close();  // Close input file.
    	
    	ofstream outfile;
    	outfile.open("Final Story.txt");  // Open output file.
    
    	for(int i = 0; i < length; i++)  // Go through entire story character by character.
    	{
    		if(story[i] != '[')  // If '[' not found yet then just output character to file.
    		  outfile << story[i];
    		else  // Else '[' found
    		{
    		  i++;  // move to next letter in story.
    			cout << "Input a ";  // Display to user.
    
    			while(story[i] != ']') // While we haven't reached ']' output user request. i.e. Noun.
    			{
    				cout << story[i];
    				i++;
    			}
    
          cout << "?   ";
    			cin >> word;  // User puts in desired word.
    			outfile << word; // Put that word in the final story.
    		}  // Go through the while loop and process rest of story.
    	}
    
    	outfile.close();	// Close output file.
    	
    	delete story;  // Free memory.
    
    	return 0;
     }
    Input File
    Code:
    TWas the night before
    [Holday]
    and all through the
    [Noun],
    not a
    [Noun]
    was
    [Verb]
    ,not even your
    [Noun].
    All the children were tucked all snug in their
    [Noun],
    with visions of
    [Food]
    dancing in their heads.The stockings were hung by the chimney with
    [Verb],
    in hopes that
    [Person]
    soon would be there.I in my kerchief and ma in her
    [Noun],
    had just
    [Verb]
    down for a
    [Adjective]
    winter's nap.When up on the roof on I
    [Verb]
    such a
    [Adjective]
    ,I jumped from my bed to
    [Verb]
    what was the matter.When what do my
    [Adjective]
    eyes do appear,but a
    [Noun]
    and eight
    [Adjective]
    reindeer.
    Final output:

    Code:
    TWas the night before
    Valentine'sDay
    and all through the
    slums,
    not a
    bum
    was
    humpin'
    ,not even your
    mum.
    All the children were tucked all snug in their
    cells,
    with visions of
    rats
    dancing in their heads.The stockings were hung by the chimney with
    glee,
    in hopes that
    MyDrugDealer
    soon would be there.I in my kerchief and ma in her
    thong,
    had just
    layed
    down for a
    short
    winter's nap.When up on the roof on I
    felt
    such a
    jolt
    ,I jumped from my bed to
    see
    what was the matter.When what do my
    wasted
    eyes do appear,but a
    prostitute
    and eight
    sexy
    reindeer.
    Last edited by Kurisu; 02-06-2006 at 10:51 PM.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    11
    Wow you guys are awesome especially you kirusu seriously great effing code and examples thank you so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. check out this tutorial plz...even experts
    By KidMan in forum C Programming
    Replies: 1
    Last Post: 01-28-2006, 11:15 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 01:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21