Debugging code.

I have a short code that I'm trying to debug, but am a little stuck write now. Basically all the code does is have the user input a number, and it will tell whether or not the number is prime. I keep getting a
floating exception (core dumped)
error.

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
#include <iostream>
#define PROMPT "Please enter a whole number: "
#define NOT_PRIME "The number is not a prime number. "
#define PRIME "The number is a prime number. "        
#define DONE 0          /* ends successful program */                           
#define FIRST_FACTOR 2  /* initial value in for loop */                         

using namespace std;
int main(){
    int i;       /* loop counter */
	char number; /* number provided by user */
cout << PROMPT;  /* promt user */
    cin >> number;  /* wait for user input */
/* Prime numbers are defined as any number 
*         greater than one that is only divisible
*                 by one and itself. Dividing the number
*                         by two shortens the time it takes to
*                                 complete. */
    for(i == 2; i < number/2; ++i){
        if( number%i == 0 )
		{    //if divisible
		cout << NOT_PRIME << number << "\n"; //not prime
		return DONE;        //exit program
		}
	}
    /* if number is not divisible by anything
*         than it must be prime */
    cout << PRIME << number << "\n";
return 0;     /* exit program */
}


Thanks for any help.
The problem is line 20. The right operand of % should not zero. The problem is related to division by zero.

On line 19 you are using == when you should be using =.
Perfect, thank you very much!
Topic archived. No new replies allowed.