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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.