Program error

A blank line is inserted after every 5 data displayed.
Can tell me the error ? and how to fix it ..Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 #include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
	double const feet=3.28;
	int meter=0;
	double conversion=0;
	int i=0,x;
	  
	cout<<left<<setw(15)<<"Meter"<<setw(10)<<"Feet"<<endl;

	for(x=2; x<100; x+=5)
	{
	for(i=2; i<x; i+=2)
	{
	conversion=i*3.28;
	cout<<right<<setw(5)<<i<<setw(15)<<fixed<<setprecision(2)<<conversion<<endl;
	}
	cout<<endl;
	}

	system("Pause");
	return 0;
}
Line 21 causes a blank line but it's not exactly every fifth row so I don't know if that's what you're referring to.
Hello DesmondLee,

This may not be exactly what you want, but it does come close.

1
2
3
4
5
6
7
8
9
10
11
12
13
for (x = 2; x < 30; x += 5)
{
	for (i = 2; i < x; i += 2)
	{
		conversion = i*3.28;
		cout << right << setw(5) << i << setw(15) << fixed << setprecision(2) << conversion << endl;
		++count;
		if(count == 5 || count == 10 || count == 15)
			cout << endl;
	}
	cout << endl;
	count = 0;
}


Consider the first time through the loops when x = 2 the inner for loop only prints 3 lines then prints a blank line before going through the inner for loop a second time.

If this does not work let me know. I have another idea I have not tried yet.

Hope that helps,

Andy
Hi Andy. Thank for the reply @Andy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
	double const feet=3.28;
	int meter=0;
	double conversion=0;
	int i=0;
	  
	cout<<left<<setw(15)<<"Meter"<<setw(10)<<"Feet"<<endl;

	for (i = 2; i <= 100; i += 2)
	{
		conversion = i*3.28;
		cout << right << setw(5) << i << setw(15) << fixed << setprecision(2) << conversion << endl;
		if(i == 10 || i == 20 || i == 30 || i==40 || i==50 || i==60 || i==70 || i==80 || i==90 || i==100)
		{
			cout <<endl;
	    }
    }

	system("Pause");
	return 0;
}


This is my code which based from your example. It give me more understanding. I get what i want from the output. Thank you very much.
Topic archived. No new replies allowed.