# prime numbers code compile error

This is a discussion on prime numbers code compile error within the C Programming forums, part of the General Programming Boards category; hi i'm new to c and i've had trouble with the following code i got from a tutorial. i get ...

1. ## prime numbers code compile error

hi i'm new to c and i've had trouble with the following code i got from a tutorial. i get 'warning assignment to int from double' when trying to compile. if anyone could help as i'd like to know what i've done wrong or if its the compiler.

Code:
```int main(void)  //code to find the next prime number
{
int startingpoint, last, i, isprime, candidate;

startingpoint=19;  //find the next prime after 19 in this case

if(startingpoint < 2)
{
candidate= 2;
}
else if(startingpoint ==2)
{
candidate =3;
}
else
{
candidate=startingpoint;

if( candidate %2 ==0)
candidate--;

do
{
isprime= true;
candidate +=2;
last = sqrt(candidate);

for(i=3; (i<= last) && isprime; i+=2)
{
if((candidate %i)== 0)
isprime= false;
}
}while( ! isprime);
}

printf("the next prime after %d is %d. happy?\n", startingpoint, candidate);

std::cin.get();

return 0;
}```

2. >last = sqrt(candidate);
sqrt returns a double and last is an int. Because this is assigning a wider value to a narrower type, the implementation is required to warn you.

And C++ code goes in the C++ forum.

3. thank you for your help. if this includes c++ code then i'm sorry but i've been learning c and this program came from a c tutorial. though obviously not a very good one

4. >this program came from a c tutorial
>>std::cin.get();
That's a pretty sad C tutorial, maybe you should just get a good book.

5. perhaps you could help me further by telling me what equivilent code i could use from the c language to replace this 'std::cin.get()'.

6. Well you could have a look at this for an idea of what is going on with your code, and how you might change it. Also, you need to include at least two header files for some of the functions you use in your code.