Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to insert a line every 10 numbers displayed in C++?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i is incremented twice. Do not increment it again in the if condition, and just use the following:

if (i % 10 == 0)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading