Bench's Profile User Rating: *****

Reputation: 856 Master
Active Posts:
2,339 (0.9 per day)
20-August 07
Profile Views:
Last Active:
User is offline Sep 04 2014 06:02 PM

Previous Fields

OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
Expert In:

Latest Visitors

Icon   Bench has not set their status

Posts I've Made

  1. In Topic: Is there a better way to parse & format phone numbers?

    Posted 4 Sep 2014

    RegEx is specifically intended for pattern matching - so it's a very appropriate tool for parsing data such as phone numbers.

    In general, there's never an absolutely right/wrong way to create working code; although the preferred solutions are nearly always the simplest ones, and the ones which clearly show your intent at the time of writing it (i.e. intent to solve a particular problem - code which is expressive enough that its rationale is clear to anyone else reading - or yourself in 6 months time).

    While RegEx syntax can very easily become cryptic (some people avoid it for this reason), and 'how-it-works' is not always clear (especially not to those who don't use RegEx very often), the intent of code which uses RegEx pattern matching is often a lot more obvious, even if the pattern itself is hard-to-grok by casually glancing over it. RegEx itself is usually a lot more powerful and flexible for parsing nontrivial string formats too.

    As an example - the string 1-888-8888 could be matched with a pattern \d-\d{3}-\d{4} (You can validate the RegEx itself with any regex tool - e.g. ) - with a little tinkering, you could extend that pattern to match different ways of expressing phone numbers.

    There's some decent example code for std::regex here (assuming you're using a recent C++11 compiler) -

    It's also 'OK' to do things with a whole bunch of nested conditional/loops as well, but you need to consider how easy it is for code like that to get out-of-control - just a few special cases "over here" can lead to a few more hacks and special cases "over there" (particularly when you're dealing with magic numbers and fixed positions within a sequence); and you can easily end up with a couple of loops/If statements turning into a multi-headed hydra with dozens of paths and probably code which may be less flexible and whose intent is murky.
  2. In Topic: Logic error on C/C++ input-output

    Posted 13 Sep 2013

    char is a single character (single byte) in memory. the getchar() function will read a single character value; however, typing multiple characters as your input (for example "12") is classified as a string of characters.

    If you type in "12" then you're looking at 2 chars - '1' and '2' - that won't fit into a single char, so getchar() will only return '1'.

    Furthermore, the character code for '1' is not the same as integer 1. (Assuming you're using a system with an ASCII character set, then character '1' has an integer value of 49 -

    If you're looking to read a different type, such as an integer, take a look at the scanf family of functions: http://www.cplusplus...e/cstdio/scanf/

    As a general comment, in visual studio you can set break-points to examine your code while it's running, in order to give yourself a way to inspect what's happening in memory while your program is running. If you click on a line in the code window and press F9 (or through the menu DEBUG -> Toggle Breakpoint), you'll get a red 'dot' next to the line. When you run your program with F5, the execution will pause at that line, and you will be able to mouse-over num and inspect its value - doing this can help show you exactly what's going wrong.
  3. In Topic: Not sure how to go about this program.

    Posted 13 Sep 2013

    Is your compiler showing any warnings related to loss of precision? Rememebr that an int is only capable of storing whole numbers (integers). It's also worth noting that float has very limited precision (on a typical 32-bit desktop, you can expect float to be accurate for no more than 7 significant figures).

    The default floating-point type in C and C++ is double
  4. In Topic: Cannot go to another level in RPG game

    Posted 4 Aug 2013

    At the top of your file (in the global scope... ) You have the following code:
    int Gamespeed = 100;
    int Level = 1;
    bool stopgame = false;
    int main()

    Then later on..

    	while(stopgame == false && Level == 2)
    		cout << "This is Level 2..." << endl;
    		cout << endl;
    		int Gamespeed2 = 100;
    		int Level = 2;

    You are re-declaring your variable called level within your second while loop. - You have two different variables (areas of memory) in your program, although the name of the second level causes the first level to be hidden.

    Which means that when you reach this line of code, the value of Level is 1
    	while(stopgame == false && Level == 3)

    Just a few ideas to think about:
    1) You should spend some time learning how to use your debugger - particularly so that you can "break" the execution of your program and inspect the values of particular variables; it will let you see what's really going on inside your program, and you can check whether your assumptions are right or not

    2) You've got a huge amount of repetition in your program - You could cut down the complexity (and therefore make it easier to see what's happening) if you put all of your repeated code in functions. Functions allow you to reuse the same basic program logic using different values (Values such as arrays and array sizes...)

    3) Try to avoid using "global" variables (variables declared outside of a function, such as those before your int main). When you start learning how to use functions, and your programs get more complicated, global variables can get really messy, and make your life harder when trying to find out what's really going on!

    JackOfAllTrades has written a couple of really useful guides which are worth reading:
  5. In Topic: Exam: concepts, need some clarification

    Posted 21 Oct 2012

    View PostFrozenSnake, on 20 October 2012 - 11:39 PM, said:

    Data type: A data type tells us what values a variable can contain. For example, an int can only contain integers; if the programmer would enter a number with decimals the decimals would be truncated. For example would 1.1 be 1.
    A data type also provides you:
    - Information about the sizeof (in bytes) for an an object of that data type in memory
    - An interface to objects of that type (operators form part of an object's interface as much as constructors, member functions, etc)

    View PostFrozenSnake, on 20 October 2012 - 11:39 PM, said:

    Function: A snippet of code that is used to solve the same problem several times in different parts in the program without having to re-solve it.
    However re-use of a function isn't necessary. Sometimes functions are simply used to break larger chunks of code down into smaller ones. A shorter definition of 'function' would be a named block of code

    View PostFrozenSnake, on 20 October 2012 - 11:39 PM, said:

    Polymorphism: Polymorphism is when we use a function without knowing which class it belongs too. Example on this is in the Invaders game we made, for example when we are doing collision detection. We fetch i:s x- and y-coordinates and j:s x- and y-coordinates. But we do not know if x is a ship, bullet or enemy and the same applies for j. This is handled by the program. These functions doesn’t have to behave the same as the mother class function, it has to have the same “head” but the body can be different.
    C++ has two types of polymorphism. The type you're describing here is known as Dynamic polymorphism (at runtime). a.k.a "late binding" or "dynamic binding"

    C++ additionally includes the concept of static polymorphism (polymorphism at compile time); which is more commonly used under the umbrella of Template Metaprogramming.

    Both static and dynamic polymorphism follow the same basic concept - manipulating different objects in code through a common interface without needing specific data type information about those objects

    View PostFrozenSnake, on 20 October 2012 - 11:39 PM, said:

    Capsulation: capsulation can happen on different levels and be used to hide data. Depending on level we can do different things with functions and variables.
    Do you mean Encapsulation? Note that 'implementation hiding' applies equally to the behaviour of an object (i.e. the details which describe how it works); data hiding is only one part of this.

    For example, a badly-encapsulated class called DeckOfCards might include member functions called GetNumberOfCards() and SetNumberOfCards(). Both of these are probably bad because they "leak" the internal behaviour of the object, expecting the user of the class to do the leg-work. a class modelling a deck of cards is more likely to want member functions such as DrawCardFromTop, ReplaceCardToBottom, ShuffleDeck, IsDeckEmpty etc.

    View PostFrozenSnake, on 20 October 2012 - 11:39 PM, said:

    Inheritance: Inheritance makes it possible for subclasses to inherit functions and variables from one or more classes. The subclasses will inherit both functions and variables.
    The act of inheriting a class could also be described as defining a new class whose interface and implementation are an extension of an existing class. Another word would be Specialisation.

My Information

Member Title:
D.I.C Lover
32 years old
August 15, 1982
Years Programming:
Programming Languages:
C, C++, C#

Contact Information

Website URL:
Website URL  http://


Page 1 of 1
  1. Photo

    Sy-Coderz Icon

    23 Jun 2012 - 09:47
    bro please add me at :
    add me please i need some help
    i wait u
  2. Photo

    OLH064 Icon

    28 Aug 2011 - 11:09
    That is the best signature ever.
  3. Photo

    Jeff H Icon

    19 Jun 2011 - 00:54
    Hey Bench,
    I have dual monitors and was looking over at the other one as I was trying to give you a + rep and accidently hit the - rep.
    Just let me know what I need to do to help get it changed. I already left a reply in the thread.
  4. Photo

    Jeff H Icon

    19 Jun 2011 - 00:54
    Hey Bench,
    I have dual monitors and was looking over at the other one as I was trying to give you a + rep and accidently hit the - rep.
    Just let me know what I need to do to help get it changed. I already left a reply in the thread.
  5. Photo

    sleepybug Icon

    20 Feb 2010 - 06:45
    hey bench!!thanks for the simple code concerning node,pointer and linked list ,you after learning pointers i understand your that program much more clearly and its simple working..thanks for help buddy.
  6. Photo

    neptunusmaris Icon

    16 Feb 2010 - 10:56
  7. Photo

    CodingDesire Icon

    16 Feb 2010 - 09:21
    Hello there, thank you very much for your help!
Page 1 of 1