Hi, I'm a beginner programmer, and I need to write this program for homework for a college-level class. I've tried to run it numerous times, but I continually get the errors. I want to know if someone can check it over and let me know what I'm doing wrong, which is most likely everything. Thanks for any help!
Write a program that reads a string containing exactly four words, (separated by * symbols) into a single string object. Next, extract each word from the original string and store each word in a string object. Then concatenate the words in reverse order to form another string. Display both the original and final strings. (Hint: To extract the words, you should use the 'find' member function to find each symbol *, assign the characters up to the * to one of the four string objects, and then remove those characters from the original string.)
Code:#include <iostream> #include <string> using namespace std; int main() { //First, I will declare the variables string original; int remove_1; int remove_2; int remove_3; int remove_4; string star; string word_1; string word_2; string word_3; string word_4; string reverse_1; string reverse_2; string reverse_3; string reverse_4; string final; //Next, I will gather the inputs cout << "Please enter your words..." << endl; cin >> original; cout << "Please enter your method of spacing..." << endl; cin >> star; //Next, I will separate the words remove_1 = original.find(star); reverse_1.assign(original, 0, remove_1); original.erase(0, remove_1); remove_2 = original.find(star); reverse_2.assign(original, 0, remove_2); original.erase(0, remove_2); remove_3 = original.find(star); reverse_3.assign(original, 0, remove_3); original.erase(0, remove_3); remove_4 = original.find(star); reverse_4.assign(original, 0, remove_4); final = reverse_4 + "*" + reverse_3 + "*" + reverse_2 "*" + reverse_1; //Next, I will compile the new string and display it on the screen cout << "The original string was: " << original << endl; cout << "The reversed string is: " << final << endl; return(0); }