Need help reversing a sentence

Hello,

I'm currently having trouble with an assignment that is due in 50 minutes..
The instructions are to ask the user for a name or phrase then display the name/phrase backwards. He wants use to do it using a function (void). So far it can put a word backwards but it can't do a phrase (multiple words). It just repeats the first word, what am I missing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

void reverse_String(string& greet, int n,int i){

  if(n<=i){return;}

  swap(greet[i],greet[n]);
  reverse_String(greet,n-1,i+1);

}

int main() 
{
  
  string name;
  cout << "Please enter a name or a phrase " << endl;
  cin >> name;
  reverse_String(name,name.length()-1,0);
  cout<<"String after reversal: "<<name<<endl;
  
}
getline( cin, name );
Thank you! I completely forgot about that
Topic archived. No new replies allowed.