Batch Processing Incorrect Output

I have a file with the integers
17 24 3 247 -5 49
and the assignment is to read the numbers and determine if it's a prime number or not. The program's also supposed to stop when a negative value is read and display a message stating how many integers were processed.

My output is
17 is prime
24 is not prime
3 is not prime
247 is not prime
4 numbers were processed.

It would output "16 numbers were processed" but I put "- 12," so that's also an issue. How would I get the output to be correct?

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()
{
  int number;
  int count = 0;
  int a;
  
  cin >> number;

  while(number > 0)
    {
      
      
  for(a = 1 ; a <= number ; a++)
    {
      if(number % a == 0)
	{
	  count++;
	}
    }

  if(count == 2)
    cout << number << " is prime" << endl;
  else
    { 
      cout << number << " is not prime" << endl;
    }
  cin >> number;
    }

  cout << count - 12 << " numbers were processed" << endl;
  
 
 return 0;
}

Last edited on
Topic archived. No new replies allowed.