Manipulating Integer/Double Variables
Integers/Doubles are two popular number data types that are mostly used for counting, summing, averaging and other mathematical calculations. There are many things you can do with numbers, especially when using them in conjunction with loops. You probably already know the basics, so this section will teach you some cool stuff that you can do with these data types.
The first thing to note is that, unlike strings, integers don't require a specific library for them to function.
To avoid repetition, here is an example that uses integers for counting:
What this code does is that it inputs a number from the user. The For loop then keeps on executing until counter (which is 0) is less than or equal to the user input. Each number is then displayed on its own line going from 0 up until the value entered by the user. You'll see this example a lot, even in your own coding. Counters are very important when it comes to programming and using loops in general.
You'll find that it is easy and fun exploring the world of integers, doubles and counters. Therefore, to help you out with your journey, here are some tips for formatting your output. Note that these are part of the iostream library so you must state the library at the top of your code.
Note that the functions width() and precision() have to be entered before each output that is to be formatted. On the other hand, setf() needs to be set only once.