Write your question here.
Hi all, I am fairly new to coding and really could use some help with this exersize.
"Write a program that prints the first letter of each word in a given sentence forwards and backwards."
I was given the hint to use an array to store the first letter of every word. The goal is to have something like... "Hey there how are you" output as "Hthay" and then reversed as "yahtH".
I need to help starting off and any help or suggestions are helpful :)
I suggest getting the entire line into a buffer, then use a for loop to find all the spaces. For each space found, take the letter immediately after it and store it in another buffer as your final result. Reverse the first result with another loop for the reversed result. Make sure that you include the first letter, which is a special case because it doesn't have anything before it.
I was given the hint to use an array to store the first letter of every word. The goal is to have something like... "Hey there how are you" output as "Hthay" and then reversed as "yahtH".
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
char size[1000];
cin.get(size,100);
cout << "Name : ";
cout << size;
// now run the array in reverse
cout << "\nName in reverse : ";
int num = strlen(size); // check how many chracter the name contain
for (int i = num; i >= 0; i--)
{
cout << size[i];
}
cout << endl;
system("pause");
}