// random0.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
void prime_num(int num);
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
prime:
int num;
int msgbox = MessageBox(NULL, L"Greetings, welcome to this application designed to scan for Prime Numbers!\n~Q.A.I. (a.k.a Quantum Artificial Intelligense)", L"Run", MB_ICONINFORMATION);
cout << "Enter a number below and i shall calculate all the prime numbers from up to that number!\n";
cin >> num;
prime_num(num);
cin.get();
cout << "\nWant to scan for prime numbers again?\n1 for yes, 2 for no.";
int a;
cin >> a;
switch(a){
case 1:
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
goto prime;
break;
default:
int msg = MessageBox(NULL, L"C'ya!", NULL, NULL);
goto exit;
break;
}
exit:
return 0;
}
void prime_num(int num){
bool isPrime = true;
for (int i = 2; i < num; i++){
for (int j = 2; j < i; j++){
if (i % j == 0){
isPrime = false;
break;
}
}
if (isPrime){
cout << i << " is a prime number.\n";
}
isPrime = true;
}
}
Took me awhile to figure out what cause it to print so many lines of the same type..... But it's fixed now :D
Also, i'm also aware of the 'goto' lines, i know that they are bad, but they aren't, as long as it's not a big project.