Real easy question but I am missing something

How do I let my program check that load_factor <= .75 when I have load factor as a double type but still returns zero instead of a decimal value? Here is the code I am running

while(NotDivisbleYet=true && k<count)
            {
                  
            if(count%k==0)
                  {
                        NotDivisbleYet=false;
                        count++;

                  }
                  else
                  {
                        k++;
                  
                  }
                        if(k>=count)
                        {
                        Prime2=true;
                  
                        if(Prime2 = true)
                        {
                              load_factor=(n/count);
                        }

                              if(      load_factor >= 0.75)
                              {
      
                                    Prime2=false;
                                    NotDivisbleYet=true;
                                    count++;
                                    k=2;
                              }
                              
                        }
                  
            }
Thanks I am sure it is something easy and I am missing the answer
D_bashamAsked:
Who is Participating?
 
BenMorelCommented:
I guess this line does not provide the behavior you want :
load_factor=(n/count);

If "n" and "count" are integers, then the result "n/count" will be an INTEGER, and then type-casted to double.
For example , 3/4 will produce (int)0 , type-casted to (double)0 !

Here it is not what you want !

So you should do this :
load_factor = ( ((double)n) / ((double)count) );

See ya
Ben
0
 
Jaime OlivaresSoftware ArchitectCommented:
I guess this line:
while(NotDivisbleYet=true && k<count)
could be:
while(NotDivisbleYet==true && k<count)

and this line:
 if(Prime2 = true)
could be:
 if(Prime2 == true)

= is the assignment operator
== is the comparison operator

Good luck,
Jaime.
0
 
D_bashamAuthor Commented:
jaime. I appreciate the help but I did figure it out. And you were right. Anywasy I make a deal with you help with this question I will acept your answer. How do I take a string that I am reading from a file and find its ascII value? Thanks :)

cs
0
 
BenMorelCommented:
For your 2nd question:

A C-String is a array of ascii values! :)

For example :

char sBuffer[1024];
FILE* fp;
fp = fopen("example.txt", "rt");
fgets(sBuffer, 1024, fp);
fclose(fp);

Now if the string read is "Hello world !", then sBuffer[0] will contain ascii code for 'H', sBuffer[1] will contain ascii code for 'e', etc.!
sBuffer[i] is a 'char' type, so it's a 1-byte integer.

You can try this with this sample code :
printf("%u", sBuffer[0]); // will print "72" in our example

Ben
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.