In: Computer Science
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.
Ex: If the input is:
Hello there Hey quit
then the output is:
ereht olleH yeH
IN C++ PLEASE!
Code in c++
#include <bits/stdc++.h>
using namespace std;
//main function
int main()
{
//initializing the required variables and arrayes
string str[10],in ;
int i=0,n;
//loop for reading the input until the user enetr "quite"
or"q"
while(true)
{ //take input from user ans store in 'in'
getline(cin, in);
//checking if the input is "quite" ,"q" or "Quite
if((in =="q") ||(in =="quite")||(in =="Quite"))
//if so break
break;
//else store the data in array str
str[i]=in;
//increment the index
i+=1;
}
n=i;//storing the total count in 'n'
//loop for taking each string from array
for(i=0;i<n;i++){
//reverse function is an direct function which will reverse the
string
reverse(str[i].begin(), str[i].end());
//print the reversed string
cout << str[i]<<'\n';
}
return 0;
Screenshots
Input\output