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
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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started