thelamb 163 Posting Pro in Training

You are close actually.. it's really not that horrible.

Look at average in the .h file, and then at average in the .cpp file.
Now think of it from the compiler perspective, it sees int average( int something ); in the header file, so a function that takes an int and returns an int.

In the .cpp file, it finds int average( numbersInput ); here it has no idea what 'numbersInput' is.. and then in the function body you define numbersInput again by saying 'int numbersInput'.

So the way this works is you need to synchronize the header and the cpp file, except for the argument names, so for example:

.h file:
int average  ( int );
int average2( int thisIsAnIntVariable );
int average3( int myInt );
.cpp file:
int average ( int ) { return 4; }  // Illegal, don't know the name of the variable
int average( int myInt ) { return myInt; } // OK
int average2( int myInt ) { return myInt; } // OK (var names dont need to match)
int average3( double myDouble ) { return 4; } // ERROR

Hope that helped.

thelamb 163 Posting Pro in Training

Ask yourself questions (before asking google). And be precise!
You did not read my last post fully, as the error I mentioned is still in. Don't just do something, hit compile and google for the errors you are getting, think structurally what you want to achieve, break the problem up in pieces and step by step take them down, making changes precisely and everywhere where you need to (declaration and definition should match).

After fixing what I mentioned, think about what input is.

thelamb 163 Posting Pro in Training

Whenever you call a function, you do not need to include the argument's datatypes. For instance:

// Function that returns nothing and takes 1 int as argument
void myFunction( int myInt )
{
    cout << "Your number: " << myInt << "\n";
}

int main()
{
    int myInt = 5;
    myFunction( myInt );
}

Secondly, the declaration and definition of your Print_Results are different( on line 11, the ofstream argument is missing ).

thelamb 163 Posting Pro in Training

That's not a question, that's "Can someone please do my homework". Which unfortunately no one is going to do for you.

So, as with many problems, the first step is: break it up in parts.
-> Do you know how to open a file?
-> Do you know how to read from a file?
-> Do you know how to use arrays?
-> etc.

Maybe even those questions you can sub-divide. Then take what you think should be the first step, and try to implement it. If you don't know how... google, if you tried something but it doesn't work.. post here and give us your thoughts (how do YOU think it should by done, and why do YOU think it fails)... then someone will help you out.

Fbody commented: right on :) +1
Ancient Dragon commented: Yes, that's what I meant too. +27
thelamb 163 Posting Pro in Training

You have already done it...

Look at how you declare your 'request':

Request *request=new Request();

So 'request' is now allocated on the heap.. means you are responsible for cleaning it up (delete request; somewhere in the code).

Then, you say.. ok I want 'request' to point to a LoginRequest.

LoginRequest loginRequest;
request=&loginRequest;

So you are overwriting the previous pointer to 'new Request();' with a pointer to a local variable loginRequest.
Since loginRequest is local, it will be destroyed when it goes out of scope. Now your 'request' pointer points to garbage and there is no way that you can delete the original new Request()(remember you overwrote the pointer), so you have yourself a memory leak.

So I dont really understand why you do the first "new Request();".. doesnt this make more sense:

Request *request=new LoginRequest(); // I guess LoginRequests inherits from Request?
request->tcpMessage=line.toUtf8();
request->decodeFromTcpMessage(); 
if(request->requestType==REQUEST_LOGIN)
{
    requests.enqueue(request);
} else  // Request is not a LOGIN_REQUEST
{ 
     delete request;
}

// When you destroy the requests.. dont forget to delete the pointers.

P.S. think about your naming convention...
Is using 'requests' and 'request' a good idea? The names look very simmilar and just introduce confusion.

metdos commented: Good Point +1
thelamb 163 Posting Pro in Training

How about if...else if ?

if ( Discriminant < 0)
{
	cout << "There are NO real roots" << endl;
}else if ( Discriminant > 0 ) // if Discriminant is not smaller than 0
{
	cout << fixed << setprecision(3) << "Root 1 X Coordinate: " << Root1 << endl;
	cout << fixed << setprecision(3) << "Root 2 X Coordinate: " << Root2 << endl;
}
thelamb 163 Posting Pro in Training

You can't get root2 to output.... are you sure that you are entering values for A, B, C etc. so that Discriminant is 0? As when it's > 0 only Root1 is printed of course.

Also have a look at how you check if 'A' is non-zero. What happens if I enter a non-zero value twice in a row? Validating user-input is a very important aspect of coding, and a lot of people think lightly about it but they absolutely shouldn't.

Another note on your code... You want to check if Discriminant is < 0, == 0 or > 0... so you start with checking < 0.
If this is true ( Discriminant < 0 ), what can you say about the 'Discriminant > 0' and 'Discriminant == 0' checks? Are they useful?

thelamb 163 Posting Pro in Training
thelamb 163 Posting Pro in Training

Learn about scopes.

You have more than 1 line of code 'inside' your while loop, but how does the compiler know which code is inside the while loop?

You do not tell the compiler how many lines are inside the while loop, so the compiler assumes that there is only 1 line, directly following the while loop. So that is the cout << "something";

To tell the compiler that there are more lines, surround them with brackets ( { and } ) like:

while( expression )
{
    cout << "something";
    cout << "Something else";
}

This will print "something" and "something else" in a while loop. Without the brackets it would only print "something"

thelamb 163 Posting Pro in Training

Get ready to slap yourself in the face dgr.

You're defining the applicants variable as a local variable (a variable is only valid between the brackets ( { } ) where it is defined in.

try
{
applicant *applicants = new applicant[num];
}

After the } the applicants isn't valid anymore.

Also note that you are using 'new', so you are responsible for cleaning up the memory when applicants isn't needed anymore with 'delete[] applicants;' (it's an array so you need delete[] and not delete).

Hope that helped.

thelamb 163 Posting Pro in Training

You can keep a pointer to a b1 object in the passenger class.
So when a passenger 'spawns' you set one of the building objects in the passenger class.

Then you can call p1.building->ComeGetMe();

I think the building should then take care of calling the elevator function, because only the building knows which elevators it has (because you have 2 building you probably also have 2 elevators). If later you expand with multiple elevators you can set sort of a 'position' in the passenger that you hand over to the ComeGetMe() function and then the building calls the correct ComeGetMe() function on the correct elevator class.

I hope that made sense.

thelamb 163 Posting Pro in Training

First of all, you are not closing the 'fin' stream, but this is not the cause of your problems.

Let's check what is happening:
You create a Message object, which in its constructor opens a file and reads from it. After that the file is closed.
A second instance of Message is created, which opens the same text file again and reads from it.

The second instance will just start reading from the beginning of the file again.

** EDIT: Ok I just made a suggestion but when reading it again I realised it makes no sense... so here is a better version :P:

What you can do is promote the fin variable to a static member variable so that all of the objects you create share the same fin variable so that the second time you create an instance it will start reading where the first instance stopped.
Or, you can store a static member variable that defines how many lines have already been read, but I don't know if you can open a file and set the internal pointer at a certain 'offset', you'd have to read up on this.

So I suggest you read up on static member variables to see how you can use them for your problem.

thelamb 163 Posting Pro in Training

Ok sorry I misread your question then, I thought you were printing to the screen.

But indeed, I guess the best way to go is just compare with and without printing.

thelamb 163 Posting Pro in Training

When I started out with c++ I did some projects on projecteuler.net. I was always printing my results(in a while loop) untill one day I didn't do this and was blown away by how much faster the calculation was. So if you're going to print a lot you should ask yourself how useful that will be because in my experience it significantly slowed down my algorithm, and I didn't do anything with the output.

thelamb 163 Posting Pro in Training

Also depends on how much you are printing. Using endl can significantly slow your code if you are printing alot.

As an example when I started out with c++ I did some exercises on projecteuler.net, constantly printing in a while loop, I was blown away when at some point I decided to use '\n', and the algorithm finished in a mere seconds as opposed to minutes.

athlon32 commented: It was a great post...a lot of help :D +1