A few things in addition to what @Jamal @Jamal and @200_success @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
.As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Suggested implementation
#include <iostream>
bool isPrime(int number)
{
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main()
{
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
.As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Suggested implementation
#include <iostream>
bool isPrime(int number)
{
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main()
{
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
.As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Suggested implementation
#include <iostream>
bool isPrime(int number)
{
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main()
{
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
. (Any objections, anyone?)As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Putting it all together, how about writing like this:
Suggested implementation
#include <iostream>
bool isPrime(int number)
{
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main()
{
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
. (Any objections, anyone?)As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Putting it all together, how about writing like this:
#include <iostream>
bool isPrime(int number)
{
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main()
{
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
.As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Suggested implementation
#include <iostream>
bool isPrime(int number)
{
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main()
{
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
. (Any objections, anyone?)As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Putting it all together, how about writing like this:
#include <iostream>
bool isPrime(int number){
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main(){
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
. (Any objections, anyone?)As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Putting it all together, how about writing like this:
#include <iostream>
bool isPrime(int number){
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main(){
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.
A few things in addition to what @Jamal and @200_success already wrote:
g++
on Mac OS X won't compile this code, because of#include "stdafx.h"
and theint _tmain(int argc, _TCHAR* argv[])
signature. It's good to keep your code portable, unless you have a special reason not to.g++
can compile if you drop thestdafx.h
import and if change themain
declaration.... and since you're not using the arguments of
main
, you could just declare without any args:int main() { ... }
. (Any objections, anyone?)As you already used
true
in thecheckPrime
function, why not use it in the infinitewhile
loop inmain
, instead of1 == 1
.This may be a matter of taste, but I think
while (true) { ... }
is generally more readable and intuitive thando { ... } while (true)
.... actually, as @200_success pointed out, a
for (int currentNum = 2; ; currentNum++) { ... }
loop would be even better: this waycurrentNum
is declared in the block where it is used, eliminating potential side effects, and the counter is a natural element in afor
loop. Notice the empty terminating condition, making this an infinite loop.In
checkPrime
you named the variableint Number
, but the common convention is to not capitalize variable names, use simplyint number
instead.As @leetnightshade pointed out, place the opening curly either always on the same line as the function name ("Egyption brackets"), or always on the next line.
Putting it all together, how about writing like this:
#include <iostream>
bool isPrime(int number){
for (int a = 2; a < number; a++) {
if (number % a == 0) {
return false;
}
}
return true;
}
int main(){
for (int currentNum = 2; ; currentNum++) {
if (isPrime(currentNum)) {
std::cout << currentNum << " ";
}
}
}
This compiles with g++
without warnings and runs fine in Mac OS X and GNU/Linux. I would hope it works as expected in Windows too.