0

Help with this simple code please

My target is to create a cpp program that takes several chars as input, put them into an array and substitute all the A's with B's. At last i should print the resulting array also stating how much times a substitution occured. Console is returning me a problem related to the If conditions but i'm not understanding why the program is not working. Any help out there please? https://code.sololearn.com/cB1WmHVIyNjQ/?ref=app

8th Oct 2021, 12:59 PM
Luca Polo
Luca Polo - avatar
4 odpowiedzi
+ 2
You are using double quotes in A, B, a, b. Use single quotes as they are characters not strings. "A" --> 'A'
8th Oct 2021, 1:10 PM
Kashyap Kumar
Kashyap Kumar - avatar
+ 2
Since you are using chars you should put A, B, a and b in the single quotes (ie 'a') and not double quotes ("A")
8th Oct 2021, 1:14 PM
Michał Mróz
Michał Mróz - avatar
+ 2
Line 8: * Definition of Variable Length Array (VLA - https://en.m.wikipedia.org/wiki/Variable-length_array), a non standard method for array definition. Not compatible with some compilers. * Definition of VLA <v>, specified <n> as size, but value of <n> is not yet acquired (<n> is still zero). + Rather use dynamic memory allocation using `new` to allocate, and `delete []` to deallocate memory. https://stackoverflow.com/questions/14075194/variable-length-arrays-vla-in-c-and-c https://www.quora.com/How-can-I-use-variable-length-array-in-C++ Line 16, 17, 21, 22: * Use of double quotes for character literals + Rather use single quotes e.g. 'A' for characters Line 17, 22: * Use of == operator where = operator was in order + Rather use = operator to assign new value, == operator is used for comparison purposes Line 19, 24: + Move `i++;` outside the `if` blocks. <i> should increase disregarding the conditionals These are some issues I noticed Possible fix: https://code.sololearn.com/cXYOgbV462zZ/?ref=app
8th Oct 2021, 2:33 PM
Ipang
0
Have you tried to solve errors. In if condition you comparing with characters to string which is not allowed . Characters and string have difference too
8th Oct 2021, 2:27 PM
A S Raghuvanshi
A S Raghuvanshi - avatar