Compilation Error in "Encryption Message" (NXS1)

Problem Link : Encyrption Message
My Solution :

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";


 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:


Edited code :
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:

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]
[~/devel/hackerrank/otherpeoples]>echo "1                   
sausage" | ./a.out
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: :

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


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


I appreciate your helping nature @ssjgz. :slightly_smiling_face:

1 Like