0

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;    
    
}
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by timb89
0

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.

0

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;    
    
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.