Okay so I'm having trouble with this assignment.
-------------------
Prompt the user to enter 3 words.
Once you have all 3 words output them to the screen, in the order they were input, and
separated by a space.
Use only 2 string variables to capture all 3 words.
-------------------
Please help me with my code, I know it's wrong because it will only output one, but I can't quite figure out how to do it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
#include <string>
usingnamespace std;
int main ()
{
string input1;
string input2;
cout << "Please enter three words: ";
input2 = input1;
input2 += " ";
cout << "The words you entered are : " << input2 << ".\n";
system ("PAUSE");
return 0;
}
I think kikmekings' code outputs no words because nothing has been read from cin yet.
A solution is to use one string to capture each word (one at a time), then "sum" them into the second string using += as you go. input2 += " " + input1;