Question: /*1. Design and write a program that will accept a sentence as input, reverse the words and print the sentence out backwards. Ex: The movie

/*1. Design and write a program that will accept a sentence as input, reverse the words and print the sentence out backwards. Ex: The movie was not very true to the book. Output: book the to true very not was movie The (NOTE: You may keep the period after book if you want to.)*/

#include "stdafx.h" #include #include #include

using namespace std;

int main(void) { string sentence; string ecnetnes; string part = ""; char letter; int length = 0, position = 0, i = 0;

cout << "Enter sentence:" << endl; getline(cin, sentence);

position = sentence.length() - 1; // Set position to last character.

while (position >= 0) { letter = sentence.at(position); ecnetnes = ecnetnes + letter; // Concatenate a letter position--; }

cout << "The reversed sentence is. " << endl << ecnetnes << endl;

system("pause"); return 0; }

So my sentence is printing out back wards but it should keep the word orientation the same as before?

Please advise

Thanks

The instructions are up top

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!