I need help making it so it prints prime numbers only. Thank you for your help in advanced.
-------------------------------------------
Example of how the code should look
Prime number generators are all over the internet - just try a google search. Any question you could possibly have on this topic has already been answered a hundred times.
Please edit your post and make sure your code is [code]between code tags[/code] so that it has syntax highlighting and line numbers, as well as proper indentation.
I need it to print out like the example I have above. However I did my research before posting my question. I am not looking for an outcome that says "____ is prime" or "____ is not prime" or "number is prime" or "number is not prime"
You realize you don't have to print the exact same messages as the code you find online? You can print just the prime numbers, which is what you want to do.
You realize that if I knew how I wouldn't have asked and it would be done right now?
This file is under beginners for a reason. I'm a beginner at this. I'm new, which means I do not understand everything completely. I am still learning. I looked and I don't understand.
I would appreciate that if you will not help that you do not respond.
I am trying to help by pointing you to existing resources that can help you better than I can.
I still don't understand what specifically is confusing you. I understand the output you want, and I understand that you have done research. I can't help you directly unless you tell me specifically the thing that is confusing you.
You have a lot of different functions for one thing. Try condensing it into one function that prints the prime numbers from 2 to n. Loop through all the odd numbers from 2 to n and check if each one is prime - if it is, then print it.
#include <iostream>
usingnamespace std;
int main ()
{
int n;
cout << "enter number = ";
cin >> n;
for(int i=2; i<=n; i++)
{
//check if i is prime.
//if prime, print it.
}
return 0;
}
#include <iostream>
int main()
{
int N (0);
std::cout << "Enter a value for N: ";
std::cin >> N;
for ( int i = 2; i <= N; i++ )
{
bool isPrime = true;
for ( int j = 2; j < i; j++)
{
if ( i % j == 0 )
{
isPrime = false;
break;
}
}
if (isPrime)
std::cout << i << ' ';
}
return 0;
}