Module: (C++) Subroutines: procedures and functions - 1


Problem

7/12

Shorten program code

Problem

Rabbit Clover continues to learn programming. He has already studied the lines. Recently, he moved on to the study of subroutines, namely procedures. But he doesn't understand how to use them. Recently, Clover wanted to write a program that would print the longest words out of two sentences in a column (if there are several such words, then he would take the first one he encountered). He completely forgot about the procedures and wrote a very complex program.
Here she is: #include <iostream> using namespace std; main() { int max, n; string s1, s2,wordMax; getline(cin, s1); getline(cin, s2); max=0; s1=s1+" "; while(s1.size() > 0) { n = s1.find(" "); stringword=s1.substr(0,n); if(word.size()>max) { max = word.size(); wordMax = word; } s1.erase(0, n+1); } cout << wordMax << endl; max=0; s2=s2+" "; while(s2.size() > 0) { n = s2.find(" "); stringword=s2.substr(0,n); if(word.size()>max) { max = word.size(); wordMax = word; } s2.erase(0, n+1); } cout << wordMax << endl; } Agree, this is a rather difficult program to understand. 
Help Clover the Rabbit to improve the program by selecting the same actions in the procedure.