Solved

# Real easy question but I am missing something

Posted on 2004-10-23
162 Views
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)
{
}

{

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

LVL 55

Expert Comment

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

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

I guess this line does not provide the behavior you want :

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

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

## Featured Post

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.