Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What are you going to do with the rest of the line if the Name is more than 29 characters? Is it supposed to ignore the rest of the Name characters (skip over the excess characters) and read in the remaining characters? If that is true, then after line 76 just read all remaining charcters up to the comma

while( x != ',' && In.get(x))
    ; // do nothing line here

Now the program is read to read the float and integer (line 79). Note that the if statement on line 77 is not needed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I do not think a person of Narue's status and popularity needs to make more than one account at daniweb .

Narue has admitted that she has another account, but never said what that account name was.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 47: delete void Base_exp (int, int) = because that is illegal syntax.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I was using the trial version and it recently ran out, so apparently I'm running a "non-genuine" version of Windows right now.

Get a genuine version of Windows 7, install as a fresh install, then see if the problems still persist. Its hard telling what the os did when the free version expired.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I used to like winters but this year, i don't know actually why, i can't help mentioned season. Despite temperatures are still above 0 I'm turning into ice cube. :)

That's a sign of getting old :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if(!cookieOrdered.compare(flavors))

You can just simply write this: if( cookieOrdered == flavors[i] ) , assuming flavors is an array or vector of strings/character arrays..

>>cookieOrdered.clear();
Could also be: cookieOrdered = ""; line 8: There is really no point in using an iterator in that function. Just use a loop similar to line 13.


line 8 of the second code snippet: That is ignoring the return value of check_cookieordered().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have mis-aligned closing braces }. Delete lines 54 and 60.

line 57: already told you about that one too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read some of these links how to call C functions from VB.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 55: should be }, not {

lines 59, 60 and 61: just delete them.

line 25: If you want to display double quotes then you have to escape them, like this: cout << "Enter \"P\" for Power or \"S\" for Square Root"; line 28: put surround P and S with single quotes if( Letter_code == 'P') . Same problem on other if statements

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster


how else would the condition of the for loop work ?

Just check for end-of-string null terminator for(int i = 0; string[i] != '\0'; i++)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The value 0.1 can not be represented exactly as a double.

Salem commented: Well said +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

x1.error is not 0.1 -- its 0.100000001.

bool operator==(const real& x1, const double x2)
{
  // after substituting: 0.1 <= 0.1 is true!
    bool b;
    double x = fabs(x2-x1.value);
    printf("x = %0.15f, x1.error = %0.25f\n", x, x1.error);
    if( x <= x1.error )
        b = true;
    else
        b = false;
    return b;
}

x = 0.100000000000000, x1.error = 0.1000000000000000100000000
FALSE

Press any key to continue . . .

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can always click the "Unanswered Threads" link on the right side of the screen.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 23 and 29: You can't add an node that's allocated on the stack to the linked list. Reason: when the function returns the memory address of that node is destroyed and becomes invalid. To fix this you need to call malloc() to allocate memory for the node from the heap so that it doesn't get destroyed then the function returns.

// line 23 -- make node a pointer
linked_list* node = malloc( sizeof(linked_list));
node->next = NULL;
//
// line 29
lst->data = node; // removed the & address operator

You are going to have other problems with that insert function because all the code above does is toss the current value of lst->data into the bit bucket and replaces it with a newly allocated node. You will NOT get a linked list by doing that, but you WILL get lots of memory leaks. At line 29 you need to add the newly allocated node either to the beginning of the linked list chain or to the tail -- your choice.

If you want to add to the beginning of the list, then do this

node->next = lst->data;
lst->data = node;

If you want to add the newly allocated node to the tail of the linked list then you have to first find the tail (last node) and add the newly allocated node to it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post code or a link to the code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>The you can just concat title with first name.

That was my objection. Those two can not be joined.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It may well compile, but its far from "valid c". All you are going to achieve from those typecasts is undefined behavior. Why? An array of uint8_t can not be successfully typecast into an array of structures. It seems like what that code is attempting to do is similate a union between the structure and char array. What do you think will happen to that program if I define MAX_SIZE as 1? Or any other number less than 12 (the most likely size of the structure)?.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The you can just concat title with first name. Then the result of that
gets concated with the last name. Then finally display the final result.

Wrong answer. Those strings don't have enough space allocated to concatenate them (see original post). Each of those strings need to be copied into some buffer that is large enough to hold all the strings at one time.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>May I ask what lead you to this conclusion?

Yes, just think about it for a second.

  1. mystart is an integer pointer
  2. MyArray is an array of integers
  3. first is a pointer to a structure
  4. The compiler can not convert an array of integers into an array of structures. Well, it can by typecasting but the result will be just so much shit.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First create an temporary array to hold the values

int array[] = {Q1[0], Q2[0], Q3[0], Q4[0], Q5[0], Q6[0], Q7[0], Q8[0]};
// now for the array
for(int i = 0; i < 7; i++)
{
   for(int j = i+1; j < 8; j++)
   {
       if( array[i] > array[j] )
       {
           int temp = array[i];
           array[i] = array[j];
           array[j]= temp;
         }
    }
 }
 // now the median is the middle value of array
int median = array[4];

Once you get the above compiled and working, make a function out of it so that the function can be called for each row in the Q arrays.

int median(int Q1, int Q2, int Q3, int Q4, int Q5, int Q6, int Q7, int Q8)
{
    // calculate and return the median of the parameters
}

int main()
{
    int Q1[8], Q2[8], Q3[8] ... Q8[8];

    for(int i = 0; i < 8; i++)
    {
        int m = median( Q1[i], Q2[i], ... Q8[i]);
    }
}
mrnutty commented: Appreciate that you are helping this one. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't need to pass the length of each of those strings. The concat function can easily find the lengths itself.

Here is how to make concat() return the string

string concat(const char* title, const char* fname, const char* lname)
{
    string fullname;
    // concat all three names not shown here

   // now return the result
   return fullname;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have 64-bit HP computer, 5 Gig RAM and 750 Gig HD. At first I tried to install 32-bit Windows 7, but it had all sorts of problems because I had too much RAM and too large a HD, so I wound up erasing that and starting all over with 64-bit Windows 7.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ladyqween you question is not complete. I couldn't make out what you meant here. Sorry

It was spam.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think Dev c++ is best for small scale developement.
Its FREE. and user-friendly....

Dev-C++ is a dead IDE with an old compiler, has not been upgraded for quite a few years now. Code::Blocks on the otherhand is current, still supported, and uses the most current release of MinGW (g++) compiler. And Code::Blocks is not as buggy as Dev-C++, and its debugger actually works.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

menu Project --> Properties (bottom menu item) --> Configuration Properties --> Linker --> Input. Then on the right side of the screen, add the library name in "Additiopnal Dependencies" edit box.

Another way to do it is to use the comment pragma. Put this somewhere near the top of one of the *.cpp files #pragma comment(lib,"mylib.lib")

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 24 and 33: is_open() does not take any parameters.

line 30: you can not put string literal on that line. You have to replace that string literal with a variable name, something similar to what you did on line 21.

There are probably other errors -- I stopped reading your code there.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you looking for c++ code or pseudocode?

declare three integers, one for age, one for sum of ages, and third for number of ages entered.

in a loop
    prompt for age
    update sum
    update counter
end of loop
average age is sum divided by counter
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

IMO you need to stop using Dev-C++ and get Code::Blocks. Code::Blocks is a better IDE, uses newer version of MinGW compiler (g++), and has a better debugger. That will solve your 2nd problem.

As for your first problem, why didn't you add the other *.cpp files to the project?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Each row has 5 seats, but you don't know how many rows there will be until runtime. So the first thing you need to do is to declare a 2d array with unknown number of rows and columns, like this: char **rows = NULL; Now after asking how many rows the plane has then you can allocate the number of rows and seats in each row

const int SEATS = 5;
int nRows = 0;
cout << "Enter number of rows\n";
cin >> nRows;
char** rows = new char*[nRows];
for(int i = 0; i < nRows; i++)
{
    rows[i] = new char[SEATS+1];
    strcpy( rows, "12345" );
}

Now you are ready to display the available seats. When someone selects a seat, just replace the number in the row with an 'X' to indicate the seat has been taken.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 32: you are using the wrong operator; use == to test the two characters, not = which is assignment operator. Same problem on line 43.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, you still failed to answer my question. I made a valid suggestion in the first three sentences. Now its up to you to take it or leave it -- your choice.

>>it would still be great if you could pass your infinite knowledge on to the lowest of lowly students
I would be happy to do that -- but first you have to answer my questions. I'm not a mind reader.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume you want to delete a line from a text file, right? In that case all you have to do is completly rewrite the file, omitting the line you want to delete.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Which array to you want to find the median of? Since you want to make it very difficult for yourself, sort all eight arrays at the same time, using only one of the for testing purposes. What a swap is needed you will have to swap all eight arrays so that they are kept in order. That should have been a lot easier had you used a structure to hold all the information for one person. But since you didn't, you will just have the bite the bullet and do it the difficult way.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

summer -- I hate snow and ice in the winter because it makes driving so hazardous.

Grn Xtrm commented: Same here +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Of course that doesn't discount the possibility that you are hermaphrodite (both male and female) :)

sknake commented: ++ +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dunno what I was thinking at the time.. please forgive me.
'

Nothing like a two-year late response :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Create a new project but instead of a console project create a static library, then add the files to it.

Or, if the files are small enough just add them to your console project as if you wrote them yourself. That way you don't have to bother making libraries out of them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

getline() will permit you to enter spaces in the string. If you don't want the spaces then use >> operator cin >> this->name; , but the problem with that is the >> operator will allow you to enter more characters than what this->name can hold.

>>would this lead to memory leaks or problems further down the line?
Probably if you fail to delete[] the memory.

In c++ it is better to use std::string instead of char* because you don't have to bother with memory allocation; the class will allocate memory as necessary.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What makes you think Tomm Gunn is a guy? I know for a fact that Narue is female. So if Tomm is a guy then of course he and Narue could not possibly be the same person, unless you know of a guy who can have babies.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

turbo c++ is just too old, it won't even run on Windows 7 or Vista on PC. Get Code::Blocks, MinGW, or VC++ 2008 Express.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if this->name is a pointer (i.e. char*) then you have to allocate space for it before copying the string. Just setting with = as in your example will not work.

Name::Name(char* nm){
    this->name = new char[strlen(nm)+1);
    strcpy(this->name,nm);
}

>>Ideally i would like to stay away from the use of strings and inputting via a for loop.
Why? Just for grins, then ok it might be a learning experience. But in practice, programs don't waste their time using a loop like that.

If you want to input the name via cin then you will have to set some sort of limit so that the program doesn't get data overflow

void addName()
{
   const int MAXNAMELEN = 80;
    this->name = new char[MAXNAMELEN];
    cin.getline( this->name, MAXNAMELEN);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is a program that checks your hardware for Windows 7 compatibility. You could run it to find out if your computer can run that operating system. No point wasting your time and money attempting to install Windows 7 on hardware that it will not support.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Two things wrong with the if statement on lines 120 and 124
1) if statements must have ( and ). e.g. if( condition ) 2) = is an assignment operator, == is a boolean logic operator. You want to use == in if statements

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

An array and a list are two different things. Its a lot easier to sort an array than linked list.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What data type is date? Can we assume it is a character array since you want to enter in mm-dd-yyyy format?

After entering the date it needs to be split up into month, day and year integers. Then to test for yeap use use the mod operator % on the year, i.e. if( year%4 == 0 ) Another way to do it is to use the mktime() function in time.h, which will produce the day-of-year that your assignment is looking for. But here again you have to split the string into individual integers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Notice there are four 2-byte entries not just three. So either the format is incorrect or you didn't post the correct file contents.

how you read the text might be something like this:

char text[255] = {0};
myfile.read(text, msglen);
text[msglen] = 0; // null-terminate the string
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

About speed:
for example a double is 8 byte and a pointer is 4 byte on my system.
You say that passing a double by reference is faster.
But as I can imagine if we pass a doube to a function it can imidiately use it,
however if we pass the reference, after that the fuction has to find and read the data before using it. It takes time, or not?

accessing a double passed by value has no speed advantage over a double passed by reference. The compiler generates code in both cases so that it has to load the address of the double before using it. When passed by value the value of the double is not kept in a register -- on Intel processors there are not enough registers to allow the program to do that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Using c++ classes is going to be a little slower than C functions becuase c++ has a little more overhead to contend with. Also make sure your compiler is optimizing the code to use the computer's math coprocessor for floating point math instead of using an emulator library.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Of course it can't be deleted because the program has it open. You have to close the file before attempting to delete it.

[edit]And what ^^^ said too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could try this tutorial, but it may not work under current versions of MS-Windows.