### I have a problem

https://pastebin.com/Jquwu593
Could you guys give a look to my code because it prints me the same word averytime and i don't understand why it does that? Thanks in advice.
Last edited on
 ``1234567891011121314151617181920212223242526`` ``````void a(char word[]); void b(char word[]); void c(char word[]); void d(char word[]); void e(char word[]); void f(char word[]); void g(char word[]); void h(char word[]); void i(char word[]); void j(char word[]); void k(char word[]); void l(char word[]); void m(char word[]); void n(char word[]); void o(char word[]); void p(char word[]); void q(char word[]); void r(char word[]); void s(char word[]); void t(char word[]); void u(char word[]); void v(char word[]); void w(char word[]); void x(char word[]); void y(char word[]); void z(char word[]);``````

Why :(

Looks at the rest of the code
Why???

You do not explain at all what your code is supposed to do. It's so repetitive and unmanageable.

An integer can easily be converted into a character by a simple formula, by using the ASCII value of the integer.
 ``123456789101112131415`` ``````// Example program #include #include char int_to_char(int n) { // 'a' is equal to 97 return static_cast(n + 'a'); } int main() { std::cout << int_to_char(0) << std::endl; // prints 'a' std::cout << int_to_char(25) << std::endl; // prints 'z' }``````

You can reduce your a() function to like 3 lines once you do this. Then you can start to make sense of what your code is actually doing.
 ``12`` `````` event=rand()% 26+1; // you probably meant to do rand()%25 + 1? word[ji+1] = int_to_char(event); ``````

Also note you never change the value of "ji".

Are you allowed to use std::strings? They are much easier and safer to work with than your char arrays. Variable-length arrays are not standard in C++, so you shouldn't get used to using them.
 ``12345678910`` ``````#include #include int main() { std::string s; int length; std::cin >> length; s.resize(n); }``````
Last edited on
Those kind of errors better be detected quickly as they can cause serious problems later. Sometimes it can get a little harder but don't loose focus. If you find it a problem for you, you can always use some code security program. I have heard of called checkmarx. Not sure of their cost but sounds nice.
Anyway. good luck!
Ben.
Topic archived. No new replies allowed.