Answer to Question #56666 in C++ for Anika Shahi

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.
1
Expert's answer
2015-12-02T08:04:38-0500
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS