plz find the problem in code

plz solve the problem :
Generate the first prime number larger than a given natural number 'number'.

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<conio.h>
using namespace std;
main()
{
      int number,counter=0;
      
      cout <<"enter number : ";
      cin >> number;
     do{
      for ( int i=1; i<=number; i++)
      {
          if ( number%i==0){
               counter++;   }
          }
      if ( counter ==2){
           cout <<"number is prime = " <<number;
           }
           else
           number++;
          
           }while(number!=-99);
            
      getch();
      return 0;
      }
Do you think it might be useful to reset counter at some point?

How did you choose the termination condition on line 22? When do you expect the program to stop running?
yes , i want to stop the program, when it gives output which is 'the next prime number to the entered integer'. solve the problem with your aspect.
Topic archived. No new replies allowed.