Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Dominik ( 14 years ago )
#include <iostream>
#include <string>
using namespace std;
void flushcin()
{
cin.clear();
while (cin.get() != '/n');
}
void assertEquals ( bool expected , bool actual , string description )
{
if ( expected == actual )
cout << "OK -- " << description << endl ;
else
cout << " Failure -- expected : " << expected << ", actual : " << actual << ", " << description << endl ;
}
bool isPrime(int number){
bool prime=false;
for(int j=2;j<number;j++)
{
if(number%j==0){
return false;
}
}
return true;
}
int main(){
int number;
char c;
do{
cout << "Geben sie eine Zahl ein: "<<endl;
cin >> number;
if (!cin || number < 1){
cout << "Eingabe ist falsch" << endl;
flushcin();
}
else{
bool ausgabe= isPrime(number);
if(ausgabe==true) {
cout <<number<<" ist eine Primzahl. " << endl;
}else{
cout <<number<<" ist keine Primzahl. " << endl;
}
assertEquals (false , isPrime (1) , "1 ist keine Primzahl ");
assertEquals (true , isPrime (2) , "2 ist eine Primzahl ");
assertEquals (true , isPrime (683) , "683 ist eine Primzahl ");
assertEquals (false , isPrime (11449) , " 11449 ist keine Primzahl ");
}
cout << "Bitte geben Sie ein ""j"" ein um die Eingabe zu wiederholen" << endl;
cin >> c;
}
while(c == 'j');
return 0;
}
Revise this Paste
Children: 48338