mrnutty 761 Senior Poster

>> The thing is you can never know.

I'm not sure about that. God could potentially come down and part the Red Sea or cure everybody or whatever right on CNN's cameras. Maybe even apply for James Randi's Million Dollar Challenge. Tell James he can film the whole thing from any angle he wants to prove it's not a trick. Then we'd all know for sure that it's true. Or we might all find out for sure that it's true after we die. What we'll never know for sure is that it's false if it is indeed false (i.e. He may exist all right, just never made the big splash).

Hence the atheist position that they don't have the burden of proof on this.

Thats the thing, we can never know. All of this could be false, even science. Thats why I say we never actually know if science can prove everything or not, because one can argue that we just don't have the technology to prove this right now, but who knows if such technology will ever exist?

Lately, my heads been all screwed up thinking about god. One minute he has my heart and others I start to question( sounds like my relationship with girlfriends ). At the end, I think we can only believe. But as a side note, now atheist position have the burden of proving that its not the case.

mrnutty 761 Senior Poster

Do Science prove everything?

The thing is you can never know.

mrnutty 761 Senior Poster

Man post like this pisses me off. People should have at least the common sense to post a complete example and the error or problems they are having. They think we can read their minds or something.

mrnutty 761 Senior Poster

Make sure you have at least this :

#include <vector>
using std::vector;


struct B{};

template<typename T>
struct Node{};

int main(){
 vector< vector< Node<B> > > table;
 return 0;
mrnutty 761 Senior Poster

So do you guys think religion is just a big scam?

mrnutty 761 Senior Poster

What are your guys opinion about god? Are you guys atheists, theist, or don't care? Can we discuss about god.

mrnutty 761 Senior Poster

Yea there are some bugs in the code, It should be something like this :

size_t getDifficultyLevel(const std::string& msg)
{
  const std::string difMap = "EAH";
 
  // Doesn't this just set ans to zero ????  //Yes it does, but we aren't returns 'ans'
  char ans = 0;        
 
  // This should have been done outside of the call
  cout << msg;              
  cin >> ans;
  int level = difMap.find( toupper(ans) ); 
  return level != string::npos ? level  + 1 : level; 
}

Like I said before, that would be the general approach I would take. I didn't guarantee that the code was bug free. Anyway as for the comment about line 10, it could have definitely been done outside the function call, but to me it seems natural to do it inside the getDifficulty function, else the parameter isn't necessary. Another reason why I left line 10 there is for convenience. If the user wanted to getDifficultLevel again, it would have to cout the message again before calling the getDifficultLevel function. This leaves the chance for the user to forget that he has to print a prompt message before calling that function, whereas it is automated in the function I suggested.

And as for your question, size_t can only take positive values. When you assign it a negative value, because of the way binary works it gets overflowed and thus the number wraps around like a circular wheel. Since stl's set string::npos to be -1, it gets wrapped around and thus …

mrnutty 761 Senior Poster

Yea but the thing is, one might want to handle errors differently. So a better solution would be to create a error handling function and pass in the prompting function, in which the call could possibly look like so :

int level = tryPrompt( Difficulty ,errMsg, 5 ); //tries to prompt 5 times before quiting, displays errMsg if invalid input

in anyway, I feel the error handling should be outside the function for more flexibility.

mrnutty 761 Senior Poster

I would change everything. More specifically, stop the recursion. Here is a sample :

#include <cctype>
//#include ...
//returns the difficulty level else returns string::npos if fails
int getDifficultyLevel(const char *msg){
 const std::string difMap = "EAH";
 char ans = 0;
 cout << msg;
 return difMap.find( toupper(ans) ) + 1; //add one since index starts at 0
}
int main(){
 std::string difficultPromptMsg = "\nChoose computer difficulty level.\n(E)asy\n(A)verage\n(H)ard\n\n? ";
 int difLevel = string::npos;
 while(difLevel <= 0){
   Top_Border();
   difLevel = getDifficultyLevel( difficultPromptMsg );
   if(difLevel <= 0) cout << "\nInvalid options, please try again\n";
 }
}

That might not be perfect but its a general approach to it

mrnutty 761 Senior Poster

Note std::vector<bool> is depreciated. Its creation was pointless and a mistake. std::vector<char> is a better choice versus std::vector<bool>. But using std::bitset would be better choice than either one depending on the need.

mrnutty 761 Senior Poster

Why are you not using recursion?

mrnutty 761 Senior Poster

saw that Narue posted first but it still adds a bit more info

no. srand sets the seed, it doesnt generate random numbers. the seed is a number that rand uses to generate random numbers.

rand potentially generates large numbers but some maths is all you need to put some boundaries on it:

x = rand() % 10;

the % sign is modulus, it calculates the remainder from the division (divide by 10 in this case). so thinking about it, this means that x could only equal a number from 0 - 9.

about time(0), http://cplusplus.com/reference/clibrary/ctime/time/
time takes an argument which tells it where to store the time, if it is 0, then it returns it.

Just note that using the modulus operator works on the low order bits, although in some implementation
they are just as random as the high order ones, but for consistency one should use the high order bits. For example one could
generate a random number from 1-10 as follows.

int lowOrderRand = rand() % 10 + 1 ; // "random" number from 1 - 10 , uses low order bits
int highOrderRand = 1 + int( 10.0 * (rand()/(RAND_MAX+1)) ); // "random" number from 1 - 10, users high order bits
mrnutty 761 Senior Poster

Your algorithm isn't really mergesort, its just merge. It merges two sorted data. Check wiki for a mergesort implementation.

mrnutty 761 Senior Poster

Sorry, I miswrote it then. I was suggesting what Kanosia said -- "change animation a in a stepwise manner each update call". Didn't mean to make it look like the way it did.

mrnutty 761 Senior Poster

Just interpolate between the starting height and the ending height. And you will get a smooth function. Afterwards, apply verlet integration for smooth transitioning. In short, just animate it crouching. But realize that crouching shouldn't take much cpu. So another suggestion is to have something like this :

void display(){
 //...
 if( KEY_DOWN_PRESSED && canCrouch){
    int steps  = 2;
    const int END_X_POS = 5;
    for(int i = 0; i < steps; ++i){
        crouch( END_X_POS/float(steps) );
        redisplayPlayer();
     }
 }
}
void crouch(const int delta){
 entity[0].crouching = true;
entity[0].centre_height = PLAYER_HEIGHT / delta;
entity[0].height = PLAYER_HEIGHT / (delta/2);
entity[0].gun_position.x = 0.0;
entity[0].gun_position.y = entity[0].height - 1.0;
entity[0].gun_position.z = 0.0;
}

so the idea in above is to have multiple crouch in between starting(0) and ending(5) and display its position. This is cheaper than original suggestion and probably shows decent result.

mrnutty 761 Senior Poster

Note that usually you would initialize variables in the constructors like so :

class Point{
private:
 int x_, y_;
public:
 Point(int x , int y) 
  : x_(x) , y_(y) //called an initializer list
  {
  }

};

There is something you have to remember about the above though. It will initialize data in order
of their declaration not in the order of your initializer list. Just read this sentence a couple of times a day and it will sink in.

mrnutty 761 Senior Poster

>>What happens if the compiler supports #pragma once but it doesn't do the same thing? That's somewhat unlikely, but the potential exists. Inclusion guards always work in a conforming compiler.

What other things can it do that would affect it in a bad way? And isn't pragma once supported by major compilers?

mrnutty 761 Senior Poster

Why not $pragma once instead?

@OP: Most probably the issue is you're not linking your client's .o file with Song.o while linking.
If you're compiling and linking separately know what you're doing.
Simplest way to understand is to export a makefile from the IDE you're using and read it.

Usually the suggestion is to use both pragma once and include guards, so that it is portable and also allows the possibility of compiler optimization. I just said include guards just because.

mrnutty 761 Senior Poster

>>Is there a way I can find out which derived type 'baseItt' is pointing to? I need this to help me with saving and loading in my program.

Consider having a save function for each class instead.

mrnutty 761 Senior Poster

Remember the keyword "constant" multiple. If you put the constant in the exponent, then there would be a exponential difference and not a constant difference.

mrnutty 761 Senior Poster

What are the errors exactly? Make sure you include safe guards in the header file. For example :

#ifndef SONG_H
#define SONG_H
class Song{...}
#endif
mrnutty 761 Senior Poster

As suggested, a simple getline would get a line. Here is an example :

std::string input;
getline(cin,input);
//now input contains everything the user entered
mrnutty 761 Senior Poster

How about two scholarship to two top university. Imperial college and Duke university. Which is better? I am in a dilemma

Which one has the better program for you? Personally I would go with Duke, because they have a good basketball team, and pretty good curriculum.

mrnutty 761 Senior Poster

Thanks guys. I'm actually not gonna flip a coin. I'm going to weigh the pro's and con's between the two.

mrnutty 761 Senior Poster

You need to show more code.

mrnutty 761 Senior Poster

>>I am just looking for an example of how I can count the occurance of each number in the array numbers and assign that value to the count array.

what ideas do you have? Does not have to be code, just a general idea?

mrnutty 761 Senior Poster

Use a map or a set

mrnutty 761 Senior Poster

use the inline keyword. Note that the compiler can choose not to respect your request.

mrnutty 761 Senior Poster

Use the .get() method. Here is an example:

istream fileReader("filename.txt");
char byte;
while( fileReader.get(byte) ){
  cout << byte;
}
mrnutty 761 Senior Poster

>WEll Thank GOD, we should be celebrating then, more of things like this to come for Daniweb community members

To be honest, it's no surprise. firstPerson has an excellent mindset when it comes to programming and has given lots of good advice on the forums. Posting here is almost like getting your work experience except with the some of the best programmers in the ENTIRE world as mentors.

Keep it up firstPerson... And here's an early congratulations, a tour of the company is generally a sure fire sign that you've got the job.

Thanks man. This community has been great. Actually, I got an offer from CAD/CAM company programing in C++/opengl, and now this. So I have to decide between the two for the summer. I was thinking of flipping a coin.

mrnutty 761 Senior Poster

The second way is called composition pattern and should be the preferred way.

mrnutty 761 Senior Poster

Hey good luck man. Hope the actual interview went as well as your test.

Summer internships are a great way to get lots of experience.

Yes, it went so well that they gave me a tour of the company.

mrnutty 761 Senior Poster

The manager should use the interface provided by the car. Even if there would be an extra call, it better encapsulates and is easier to maintain and debug, if only one function controls the movement of the car. So if you make different type of parking manager, you can use the interface of the car in different ways for each manager.

mrnutty 761 Senior Poster

Looks good

mrnutty 761 Senior Poster

I have heard that Knuth actually designed an algorithm that required a GOTO. It could not be removed using flow control. I don't know more than that, but I believe it was created in response to the "GOTO's are bad and unnecessary" movement -- just to be ornery.

Well, I have heard that Chuck Norris actually designed an algorithm that required nothing

mrnutty 761 Senior Poster

>>By definition on the standard.

just to clarify, usually the standard are terminals in computers, but for other things, it could be definitely something else.

mrnutty 761 Senior Poster

Software reasons:
- It reduces code readability.
- It produces inefficient code.
- It makes code maintenance harder
- ...probably many more.

Hardware reasons:
- It is inefficient.
- Branch statement are one of the most inefficient operations, and using many of those makes the hardware work more, when it might not be necessary to use them.

Ethical reasons:
- Have some heart. It is evil to use it
- You might not 'goto' heaven, if you use it.
Miscellaneous reasons:
- A dinosaur will pop out of you computer and eat you if you do.
- Your computer will kill it self
- I will kill you
- You will be condem to goto 'bad programmer's' hell.
- A dinosaur will pop out of your tv and eat you.

mrnutty 761 Senior Poster

Thanks, It went really really well. I aced the test!

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

I got a big summer internship interview today. Wish me luck!!! I'm gonna need it.

mrnutty 761 Senior Poster

>>Because NULL is defined as ((void*)0), and that cast may be a problem in some cases

care to explain...? I never had a problem switching the two.

mrnutty 761 Senior Poster

not quite, trace through your program. Line 1 is key. The fact that you are getting sef faults means that the pointer p is not valid. Check to make sure that line 40 does executes

mrnutty 761 Senior Poster

Remember that Pointer-to-objects do not get initialized to null implicitly, you have to do that by your self

mrnutty 761 Senior Poster

Hey look at it this way, if thats what your competing with, then you're golden. People these days are just pure virtual const lazy. They have no intention to do the actual research and learn from it. But the bottom line I believe is that they have no passion for programming. See, most people that are passionate about programming, actually do research before asking question, not only because its smarter to do so, but it in effect will help one learn more. But these noobs that post here( in C++ section at least ), do not really have a passion for it. They just want to either feel cool about being able to do something similar to those hacking movies they watch, or just get their assignment done and be a mediocre person in life.

mrnutty 761 Senior Poster

I think your printing loop is incorrect, try doing this :

list<nonZero>::iterator j;
	list< list<nonZero> >::iterator i;
	for(i = rows.begin(); i != rows.end(); i++)
	{
		for(j = i->begin();j != i->end(); j++)
		{
			cout<<(*j).getColumn()<<" "<<(*j).getValue()<<" ";
		}
		cout<<endl;
	}
comSysStudent commented: Helped me out a lot +2
mrnutty 761 Senior Poster

some hints/psuedocode

1) create a std::stack of strings
2) Either read words one by one, ending with a sentential value or read the whole sentence
3) If reading words one by one, just add it to the stack else if reading the whole sentence you will have to do some parsing, google "C++ split" or something similar, most likely you will use stringstream and the add that to the stack.
4) Now just pop the stack and output the value popped

mrnutty 761 Senior Poster

yes using a condition loop :

for(int i = 0; i < size; ++i){
 for(int j = 0; j < size; ++j){
    if(grid[i][j] == 0) cout << " ";
    else cout << grid[i][j];
 }
 cout << endl;
}

in your loop you go from i = 0 to i <=size; Make sure you array is of size, size+1 for that loop to be correct, or else you a bug

mrnutty 761 Senior Poster

Yea the problem is that when the user enters 'y' or 'Y', he is actually entering that plus a newline character. The getline reads the newline character as a valid input, thus it gives you no opportunity to input a second time. One solution is to use cin.ignore() before the getline so that it ignores the newline character.

mrnutty 761 Senior Poster

An example:

std::string expression = " (2*3) + 8/9";
//expression[0] = '(';
//expression[1] = '2';
//expression[2] = '*'
//...and so on
mrnutty 761 Senior Poster

whats the problem with having an extra endl?