I am trying to insert a line every 10 numbers displayed but when I run this and enter -29 and 29, not a single line shows. Please help and thank you
int start;
int end;
do
{
cout << "Please enter a number between -30 and 0: ";
cin >>start;
} while(start > 0 || start < -30);
do
{
cout << "Pleaes enter a number between 15 and 30: ";
cin >> end;
} while(end < 15 || end > 30);
for (int i = start; i <= end; i++)
{
if (i++ % 10 == 0)
{
cout << "----------"<<endl;
}
else
cout << start << " " << end <<endl;
}
>Solution :
i is incremented twice. Do not increment it again in the if condition, and just use the following:
if (i % 10 == 0)