65 761
Assignments Done
99,3%
Successfully Done
In October 2018

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.
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions