Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is my code in Visual studios: #include <iostream> #include <string> using n

ID: 3730011 • Letter: T

Question

This is my code in Visual studios:

#include <iostream>
#include <string>
using namespace std;

string spaced(string phrase) {

for (int i = 0; i < phrase.length(); i++) {
  cout << phrase.at(i) << " ";
}

return phrase;
}
int main() {
string myPhrase;
char quitLetter

do {
  getline(cin, myPhrase);
  spaced(myPhrase);
  cout << endl;

} while (myPhrase != "Q");

system("pause");
return 0;
}

This is what is expected, so I need to get the user to input 'Q' after the intial phrase to stop collecting words and then display the output with the Function in the code.

Input:

Hello
Q

Your output

H e l l o

Q

Expected output

H e l l o

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;

string spaced(string phrase) {

for (int i = 0; i < phrase.length(); i++) {
cout << phrase.at(i) << " ";
}

return phrase;
}
int main() {
string myPhrase;
char quitLetter;

do {
getline(cin, myPhrase);
cin>>quitLetter;
} while (quitLetter != 'Q');
spaced(myPhrase);

system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote