1. Engineering
  2. Computer Science
  3. im trying to get this program to give the user...

Question: im trying to get this program to give the user...

Question details
I'm trying to get this program to give the user an option to enter a random word and then have that word included at the end of each break in the story. I can get the option to ask for a word, but can't get the inputted word in the sentence to finish it. I believe my string story is wrong. Please help!

//This program will ask a user to input three random words.
//The words will be placed within the story mode executed by the program.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    string story =   
    cout<<"There once was a guy named Fred. Fred was not a nice man at all. He would never help anyone but himself. He was so " << endl;
 
   string n,a,v;
   //reading 3 words
   cout<<"Enter a word :";
   cin>>n;
 
   cout << "Fred was always selfish and full of himself. Till one day a magic mirror landed in front of him. In one word, describe what you see? - said the mirror. " << endl;
 
   cout<<"Enter a word :";
   cin>>a;
 
   cout<<"Fred was so excited by his beautiful response, that the mirror transformed the image on glass into a hideous beast. Fred was so alarmed by what he saw, he gasped: What is this creature? Your inner reflection, said the mirror. It's so  " << endl;
   cout<<"Enter a word :";
   cin>>v;
 
   cout<<"Once Fred realized how ugly he looked inside, he decided he would change and be nice and gentle towards everyone. He turned to walk away, but quickly turn back to thank the magic mirror - who mysteriously disappeared! Fred whispered one word before leaving, (Thank you)." << endl;
 
   ofstream myfile;//to read file
myfile.open ("story.txt");//opening file
string story= " "+n+" and "+a+"\n "+v+"\n";
myfile <<story<<endl;//writing story to file
myfile.close();//closingfile
 
   return 0;
}
 
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution