So after a day or two of trying i finally found out how to do this, my question is, is there any way to do this that is more efficient without using the prime function?

#include <iostream>
using namespace std;


      int main()
{
 std::string line;
 
 int i, p, x;
 
 for(i = 3; i <=100; i++) {
       
       for(p=2; p<i; p++)
       {
                if((i%p) == 0) x = 0;
                }
                if(x != 0) cout << i << " is prime\n";
                x = 1;
                }
       
       
        
    
 getline(cin,line);
 cin.get();
 
 return 0;
}

The formatting is terrible, maybe you have a mixture of tabs and spaces. I think you have a couple misplaced braces.

how should i improve my formatting, can you please give me an example... i just get lost of what has to be where when im writing

example. Note placement of braces and spacing. For more information read this by the author of the c++ language.

#include <iostream>
using namespace std;


int main()
{
    std::string line;
 
    int i, p, x;
 
    for(i = 3; i <=100; i++) 
    {     
       for(p=2; p<i; p++)
       {
            if((i%p) == 0) 
                x = 0;
       }
       if(x != 0) 
             cout << i << " is prime\n";
       x = 1;
    }
    getline(cin,line);
    cin.get();
    return 0;
}

how should i improve my formatting, can you please give me an example... i just get lost of what has to be where when im writing

Here's a turotial on Formatting C / C++ code

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.