Written by a program, which should display the word lines in the reverse order. Runs without errors, gives to enter a string, but no output.
# include & lt; iostream & gt;
#Include & lt; String & GT;
#Include & lt; algorithm & gt;
Using Namespace STD;
INT MAIN () {
int i, k, a = 0, dl = 0;
String str;
COUT & LT; & LT; "Enter string:";
dl = str.length ();
getline (cin, str);
for (i = dl; i & gt; = 0; i -) {
a ++;
if (str [i] == '') {
for (k = i; k & lt; = (i + a); k ++) {
COUT & LT; & LT; str [k];
a = 0;
}
}
}
Return 0;
}
- “and” considers the length of each word and is reset after writing the word.
- I am new to programming, if possible, explain easier.
Answer 1, Authority 100%
Here is the working code:
# include & lt; iostream & gt;
#Include & lt; String & GT;
#Include & lt; algorithm & gt;
Using Namespace STD;
INT MAIN () {
int i, k, a = 0, dl = 0;
String str;
COUT & LT; & LT; "Enter string:";
getline (cin, str);
dl = str.length ();
for (i = dl; i & gt; = 0; i -) {
if (str [i] == '') {
for (k = i + 1; k & lt; = (i + a); k ++) {
COUT & LT; & LT; str [k];
}
a = 0;
cout & lt; & lt; "";
}
a ++;
}
for (int i = 0; i & lt; dl; i ++) {
if (str [i] == '') break;
COUT & LT; & LT; str [i];
}
Return 0;
}