Question #56666

Write a program that prompts the user to enter phrases (can contain spaces) until they say they’re done, then prints out the phrases in the reverse order they were entered. You must use an array.

Expert's answer

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

int main() {
vector<string> vec;
string str;
getline(cin,str);
while(str.compare("done")!=0) {
vec.push_back(str);
getline(cin,str);
}
for(int i=vec.size()-1; i>=0; i--) {
cout<<vec[i]<<endl;
}
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS