Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

C30N9

Members
  • Content count

    1331
  • Joined

  • Last visited

About C30N9

  • Rank
    Senior Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Single Status Update

See all updates by C30N9

  1. ... And this is crazy
    But here's the code
    So give suggestions, ideas, feedback, thoughts, maybe?

    code:
    Array
    Anyways, I need help in several things:
    - How do I put limits for inputs to one kind of variables?
    - How do I convert variables? (Integers to Strings and vice-versa)

    1. Infinite Ammunition

      Infinite Ammunition

      C30N9 said:

      Anyways, I need help in several things:
      - How do I put limits for inputs to one kind of variables?


      This is unclear; do you mean how to enforce limits like e.g. entering only a number? I notice that the program enters an infinite loop if I type a letter when it asks for my HP, is this what you're asking about preventing?

      - How do I convert variables? (Integers to Strings

      code:
      Array

      and vice-versa)

      code:
      Array
      Haven't tested these and it's been a while, they're probably considered evil now for not doing it all through Boost or whatever; DW's resident source port hackers could probably offer alternatives and describe all the special use considerations and all that

      Also god damn I forgot how senseless this language is

    2. C30N9

      C30N9

      Infinite Ammunition said:

      This is unclear; do you mean how to enforce limits like e.g. entering only a number? I notice that the program enters an infinite loop if I type a letter when it asks for my HP, is this what you're asking about preventing?


      What I meant is to force the user to only type in integers, because if the user writes a double number (decimal values) on an integer the program will crash. Same for other variables.

    3. fraggle

      fraggle

      First of all, congratulations! You're obviously making progress in learning programming.

      The first thing that stands out is that you're using goto. Don't use goto. Your code is pretty much impossible to follow because you use it. Even if you ignore all the rest of my comments, this is the most important thing you should take away and learn from this. At your level of expertise, if you're using goto, you're making a mistake.

      Keep lines short. Some of the comment lines at the start of the file are hundreds of characters long. If you have a long line, break it into two lines (80 columns is a good guide for maximum line length). This applies to code as well as comments. Even if you have a huge monitor that lets you fit all of it on the screen at once, it's still harder to read than using short lines.

      You have constants defined using #define. Firstly, in C++ it's usually considered best practise to use 'const' instead of #define, eg.

      code:
      Array
      Secondly, don't define constants in the middle of your code: put them at the top of the file, underneath the #includes. This usefully separates up your file into logical sections.

      Your code has some bits like this:
      code:
      Array
      In this context, '5' is what's called a "magic number": a number written in the middle of your code without any context for what it represents. It's best to use constants instead because they implicitly explain what the number represents, eg. "player_weapon_choice_actual > MAX_WEAPONS"

      If possible, try to split your code into small functions, where each function only does one job. Long, complicated functions are difficult to follow: if it's hard to follow it's hard to be sure that it functions correctly. When you have a small function you can examine it in isolation.

    4. Show next comments  3 more
×