Compilation Error in "Encryption Message" (NXS1)

Problem Link : Encyrption Message
My Solution : https://ideone.com/SS2bN0

I’m getting a compilation error, so what should I do to get proper ISO C++ Conversion?
Please help. :slight_smile:

Instead of

 if (S[i] == "a"){
            S[i] = "d";
        }

do

 if (S[i] == 'a'){
            S[i] = 'd';
        }

and so on for all other letters. Or even better - write it in a way that doesn’t require 26 if statements :slight_smile:

3 Likes

Edited code : https://pastebin.com/1dXnbfNn
But why is this SIGSEGV ???

And you have also given the return type as string in the function.

1 Like

in case it’s not clear: @chitreshapte 's post above tells you why you’re getting SIGSEV:

[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling v_taken-NXS1.cpp
v_taken-NXS1.cpp: In function ‘std::__cxx11::string Convert(std::__cxx11::string)’:
v_taken-NXS1.cpp:5:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<S.length(); i++){
                   ~^~~~~~~~~~~
v_taken-NXS1.cpp:86:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
Successful
[simon@simon-laptop][13:46:01]
[~/devel/hackerrank/otherpeoples]>echo "1                   
sausage" | ./a.out
vdxvdjh
v_taken-NXS1.cpp:4:8: runtime error: execution reached the end of a value-returning function without returning a value
1 Like

I still don’t get it, can you correct my code?

Declare Convert to return void instead of string.

1 Like

I put void(string S) instead of string(string S) it’s giving WA???
Btw before 2-3 posts I have attached my new code

Please just link to your latest submission with each new post you make - it’s hard to keep track, otherwise.

1 Like

Sure. Here’s the latest :grinning: :
https://ideone.com/RumegY

All inputs are UPPER CASE, as should be all your output.

Edit:

Your solution doesn’t work with the sample testcase - please get that working first :slight_smile:

2 Likes

I appreciate your helping nature @ssjgz. :slightly_smiling_face:

1 Like