Im really new to C++ and im working through the book Programming: Principles and Practice Using C++. Were working on the problem to find all prime numbers between 1 - user given number. Now I got that part down. I now understand that the sqrt(i) would make the loop shorter but, Im not sure what to check for to see if its a prime or not in my if - else statements.
#include<vector>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
vector<double> prime_numbers;
double num;
cout << "Please enter a number so we can find the primes for it: " << flush;
cin >> num;
for (int i = 2; i <= num; i++) {
for (int j = 2; j <= i; j++) {
// cout << sqrt(i) << "\t";
// Check to see if Value of i is incremented correctly
// Check to see if value of j is incremented properly before returnign to i
//cout << i <<"\t" << j << endl;
if (j == i) {
prime_numbers.push_back(i);
}
if (i % j == 0) {
break;
}
}
}
for (double x : prime_numbers)
cout << x << " | ";
return 0;
}