Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this c++ program? I almost have it down but the output of what I have is just a little bit

Can someone help me with this c++ program? I almost have it down but the output of what I have is just a little bit off.

-what the output needs to look like-

$ ./scramble.out Welcome to Reverse-the-words! Enter your sentence, word or phrase: Work please Your phrase with all of the words reversed is: kroW esaelp Would you like to reverse words in another phrase? [Y}es or [N]o Y Welcome to Reverse-the-words! (etc.)

my current output-

$ ./scramble.out Welcome to Reverse-the-words! Enter your sentence, word or phrase: please work Your phrase with all of the words reversed is: esaelp Your phrase with all of the words reversed is: esaelp krow Would you like to reverse words in another phrase? [Y}es or [N]o N $ ./scramble.out Welcome to Reverse-the-words! Enter your sentence, word or phrase: Work please Your phrase with all of the words reversed is: kroW Your phrase with all of the words reversed is: kroW esaelp Would you like to reverse words in another phrase? [Y}es or [N]o Y Would you like to reverse words in another phrase? [Y}es or [N]o N

-the code I have so far-

#include 6 #include 7 #include 8 9 using namespace std; 10 11 int main() 12 { 13 //var 14 char answer; 15 bool moreprocessing; 16 17 //welcome 18 moreprocessing = true; 19 cout << "Welcome to Reverse-the-words!" << endl; 20 21 //loop 22 while (moreprocessing == true) 23 { 24 char c ='o'; 25 string s, result =""; 26 //input 27 cout << "Enter your sentence, word or phrase: " << endl; 28 //processing 29 do 30 { 31 while (c != ' ') 32 { 33 cin >> s; 34 result += string(s.rbegin(),s.rend()) + " "; 35 c = getchar(); 36 //string 37 cout << "Your phrase with all of the words reversed is: "<< result << endl; 38 } 39 //run loop x2 40 41 cout << " Would you like to reverse words in another phrase? [Y}es or [N]o" << endl; 42 cin >> answer; 43 if (answer =='y' ||answer =='Y')

44 moreprocessing = true; 45 else 46 moreprocessing = false; 47 } 48 while ( answer == 'y' || answer == 'Y'); 49 } 50 51 return 0; 52 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

2. Identify and choose outcomes to evaluate a training program.

Answered: 1 week ago