break & continue !! Help


Here in my code every thing works correctly except the break; and continue;
what is the problem !!!

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
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
using namespace std;
int main()
{

	float sum = 0;
	float n;
	cout << "Enter the number please: " << endl;
	cin >> n;
	cout << "The reciprocal of " << n << " is : " << (1/n) << endl;

	while( sum < 10)
	{
		for(int i=0;i<10;i++)

			if(cin == 0) // the loop should exit 
				break;
		    
		     if(n == 1)// then nothing should be added 
				 continue;

			 if(n == n)
		{
			sum =  sum + (1/n);
			cout << "Enter the number: " << endl;
			cin >> n;
			cout << "The reciprocal of " << n << " is : " << (1/n) << endl;

		}
		sum++;	
	}
			cout << endl;
			cout <<"The sum is : " <<  sum << endl;
			cout << endl;

			 return 0;
	}

You can't have statements between the loop statement and the loop's scope. You probably want to put the checks inside the loop itself, like so:
1
2
3
4
5
6
7
for(int i = 0; i < 10; ++i) {
    if(cin == 0) break;
    else if(n == 1) continue;
    else {
        // your code
    }
}


aha, thanks :>
Topic archived. No new replies allowed.