I have some trouble with the parameters (this is my first attempt of using two functions) when constructing the function and calling it.
Here is the debugger's error:
I:\c++\11_Tombos feladatok-beszuras_torles\19.cpp||In function 'bool isPrime(int*)':|
I:\c++\11_Tombos feladatok-beszuras_torles\19.cpp|11|error: 'i' was not declared in this scope|
I:\c++\11_Tombos feladatok-beszuras_torles\19.cpp|16|error: 'i' was not declared in this scope|
I:\c++\11_Tombos feladatok-beszuras_torles\19.cpp||In function 'int main()':|
I:\c++\11_Tombos feladatok-beszuras_torles\19.cpp|34|error: too few arguments to function 'bool isPrime(int*)'|
I:\c++\11_Tombos feladatok-beszuras_torles\19.cpp|9|note: declared here|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
And here is the code:
#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
bool isPrime(int t[])
{
for(int j=2; j<=sqrt(t[i]); j++)
{
if(t[i]%j==0)
return false;
}
if(t[i]<2)
return false;
return true;
}
int main()
{
int t[50], n, i;
cout<<"Size of array: ";
cin>>n;
for (int i=1; i<=n; i++)
{
cout<<i<<". Element: ";
cin>>t[i];
}
i=1;
while(i<=n)
{
if(isPrime())
{
for(int j=n; j>=i+1; j--)
{
t[j+1]=t[j];
}
t[i+1]=99;
n++;
i=i+2;
}
else
{
i++;
}
}
for(int i=1; i<=n; i++)
{
cout<<t[i]<<", ";
}
cout<<"\n";
system("pause");
return 0;
}
I know that system("pause") is slow and it's not recommended etc. Don't blame me for using it (suggest something else instead).