I want to print a rang of numbers according to the intervals between them.
E.g minimum: 3, maximum: 12 and the interval is 3 should print something like 3,6,9,12.
However, i am struggling with the needed logic to achieve this aim.
In the example with max=12, you want to print the maximum value, so the condition should be add<=max. Also be sure to print a space after each value. I would change the for loop so that it iterates the actual values:
1 2 3
for (int val=min; val<=max; val+= intvr) {
cout << val << ' ';
}
I think the pseudocode would be something like this:
-Get minimum number
-Get maximum number
-Get interval
-number is minimum
-As long as number is lower or equal to maximum number
----display number
----increment number by interval
Hope this helps
Edit: The only thing that you need to work on is your for loop I think, nothing big though: