I have to make my program display days 1-30 along side numbers increasing by 5 each day beginning with 6 on the first day. I wrote 2 for loops on separate tabs but now I want to know if its possible to combine them into 1. I'm still new to c++ so any tips appreciated. Thank you.
Yes! That's what I was looking for. Thank you. Here is the final piece if anyone was interested.
Well, it's a piece of code that looks like it was written by someone who was guessing at what he was doing. As I mentioned, there is no need for nested loops (and indeed, you might as well not have one here, because the outer "loop" will only ever be executed one time.)
This is entirely equivalent:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
int start = 6;
constint increase = 5;
for (int day = 1; day <= 30; ++day)
{
cout << day << " " << start << '\n';
start += increase;
}
system("PAUSE");
}