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;
}
CodePudding user response:
i
is incremented twice. Do not increment it again in the if
condition, and just use the following:
if (i % 10 == 0)
CodePudding user response:
As said by Nimish Shah you're incrementing i
twice. Besides, you're initialising i
equal to start
, that makes the code influenced by the value of start
. Try to consider the following code instead:
for (int i = 0; start i <= end; i )
{
cout << start << " " << end <<endl;
if ((i 1) % 10 == 0)
{
cout << "----------"<<endl;
}
}
In this way you print a line exactly after ten numbers