i want to make a prgoram that will read in a set of numbers and determine whether or not they are prime numbers, this is what i got so far any ideas?

#include <iostream>
#include <queue>
#include <vector>

using namespace std;


int main()
{
    queue <int> input;
    queue <int> prime;
    int inputNum;
    int temp;

    cout << "Type the numbers, ending with 0: " << endl;
    
    while(!inputNum == 0)
    {           
         cin >> inputNum;
         
         if (!inputNum == 0)
         {
              input.push(inputNum);
         }
    }
    
    while(!input.empty())
    {
         temp = input.front();
         
         for (int i = 2; i <= 9; i++)
         {
              if (input.front() % i != 0)
              {
                   prime.push(temp);
                   cout << prime.size();
              }
              
         }  
         
         input.pop();                   
    }
    
      
    while(!prime.empty())
    {
         cout << prime.front() << endl;
         prime.pop();
    }


    system ("pause");
    return 0;    
    
}

Recommended Answers

All 3 Replies

A prime number is a number which when divided by every integer greater than one and less than itself, will never leave the remainder zero.
Now check out your for loop. Is this what your for-loop checks? No.

So, re frame your for-loop.

Avoid the use of system("pause"); (reason)
Use cin.get(); instead :) ...

oh ok i got it.... for any one who wants it...

#include <iostream>
#include <queue>
#include <vector>

using namespace std;


int main()
{
    queue <int> input;
    queue <int> prime;
    int inputNum;
    int temp;
    int count;

    cout << "Type the numbers, ending with 0: " << endl;
    
    while(!inputNum == 0)
    {           
         cin >> inputNum;
         
         if (!inputNum == 0)
         {
              input.push(inputNum);
         }
    }
    
    while(!input.empty())
    {
         temp = input.front();
         
         for (int i = 2; i < temp; i++)
         {
              
              if (temp % i != 0)
              {
                   count++;
              }                      
         }  
         
         if (temp - 2 == count)
         {
              prime.push(temp);     
         }
         
         count = 0;
              
         input.pop();                   
    }
    
    cout << "The prime numbers are: " << endl;      
    
    while(!prime.empty())
    {
         cout << prime.front() << endl;
         prime.pop();
    }


    system ("pause");
    return 0;    
    
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.