Hey... thank you all for your help.
I tried to fix my code. Just as a reminder, this was the question:
The following program segmant asks the user for his or her first name in main(). Write a function that reverses the name in the array so that main() can print the reversed name. To make it easy, assume that the user name is always five characters long ("Jerry" or "Peter", for example).
This is my new code:
How come it doesn't work? Not all the characters reverse.Code:#include <iostream> using namespace std; rev(char name[6]); main() { char name[6]; cout << "What is your first name (5 letters, please)? "; cin >> name; rev(name); for(int a=0; a<5; a++) { cout<<name[a]; } return 0; } //from here is what I added rev(char name[6]) { char temp; temp = name[0]; name[0] = name[4]; name[4] = temp; temp = name[1]; name[0] = name[3]; name[3] = temp; return 0; }
Thanks, and looking forward for the answer...