Solved

Real easy question but I am missing something

Posted on 2004-10-23
162 Views
Last Modified: 2010-04-01
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
0
Question by:D_basham
    4 Comments
     
    LVL 55

    Expert Comment

    by:Jaime Olivares
    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
     

    Author Comment

    by:D_basham
    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
     
    LVL 7

    Accepted Solution

    by:
    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
     
    LVL 7

    Expert Comment

    by:BenMorel
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now