+ 2
On the Extra Terrestrial problem on the code coach, my code output was the same as expected output still i failed the test cases
#include <iostream> using namespace std; int main() { string word; string word_arr[20]; int length; cin >> word; length = word.length(); for(int i = length; i >= 0; i--){ cout << word[i]; } return 0; } //please can someone tell me what went wrong? //I'm meant to reproduce a given word in reverse //thanks
3 Antworten
+ 6
Since a string works similar to an array, its last character is at the position
length() - 1
and not
length()
which you should keep in mind when initializing the running variable.
+ 1
Oooh.... .Thanks
Ive done it... 😅😅
+ 1
Can you tell me why the array size is 20?