Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
If the user inputs "The quick brown fox jumps over the lazy old dog." the program should read back ".god dlo yzal eht revo spmuj xof nworb kciuq ehT". The program should be able to read any sized input. I am only able to get it to reverse one word because it will not read every word in the phrase.

What I have tried:

I was able to get my program to reverse one word but thats it. The user can enter "The quick brown fox jumps over the lazy old dog." but it will only return "ehT", and I need it to reverse every word that a user inputs of any size so it would return ".god dlo yzal eht revo spmuj xof nworb kciuq ehT". But I am unsure how to make my program do this.
Posted
Updated 26-Sep-17 11:57am
Comments
Richard Deeming 26-Sep-17 14:12pm    
If you want us to help you fix your code, then you need to show us your code.

Click "Improve question" and update your question with the relevant parts of your code.

Start at the end of the phrase, don't bother with words at all. Then step backwards through the string character by character until you reach the beginning.

But this is your homework, not mine, so I'll give you no code!
 
Share this answer
 
Hey man, it is C++ after all!
C++
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  string s{"The quick brown fox jumps over the lazy old dog."};
  reverse(s.begin(), s.end());
  cout << s << endl;
}
 
Share this answer
 
Comments
jeron1 26-Sep-17 18:29pm    
Absolutely! +5
CPallini 27-Sep-17 1:38am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900