plzzz help ......... i need a help

i need a help ..... in this code i'm truing to to enter the value x then the program should print message to show whether the x is prime number or not useing for loop

the teacher gave us a hint : you may need to use the idea of flags (Boolean variable)
but when i start the program and enter a value the program stop working plzzzz help me what to do :(
this is my program so plzz help me :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;
int main()
{
     int x;
     cout<<"please enter a vaule :"<<endl;
     cin>>x;
     for(int i=0;i>=0;i++) // i dont now if the counter is correct 
	{
		if (x%i!=0)
		cout<<x<<" is a prime"<<endl;
	else 
		cout<<x<<" is a not prime"<<endl;
	}
}


Last edited on
First, use indentation and code tags.

You are dividing x by zero on the first loop iteration.

Also, your for loop is incorrect (or, better, it does some useless work). The first part, "i;", doesn't mean anything. Since you initialize i at the beginning, you can leave that out, or replace it by "i = 0" and remove the initialization.

1
2
3
4
5
for(i = 0; i <= 6; ++i)

// or

for(; i <=6; ++i)
thanks alot .... :)
but i need to ask you more question about it
the techer gave us A HINT :: you may need to use the idea of flags
and i realy dont now how to use it
i try to do this but my progam stop working plzz plzz help :(
1
2
3
4
5
6
7
8
9
10
int x;
cout<<"please enter a vaule :"<<endl;
cin>>x;
for(int i=0;i>=0;i++) // i dont now if the counter is correct 
	{
		if (x%i!=0)
		cout<<x<<" is a prime"<<endl;
	else 
		cout<<x<<" is a not prime"<<endl;
	}
Topic archived. No new replies allowed.