mrnutty 761 Senior Poster

"This 2 pieces of code is equal"

well mostly the initializer list is more optimal than the second way.

mrnutty 761 Senior Poster

I think this is supposed to be a recursive pow() function.

mrnutty 761 Senior Poster

"so far I don't see a big difference between a class and a function "

WOW. Read Me

mrnutty 761 Senior Poster

.

mrnutty 761 Senior Poster

glut/opengl/c++ is easy to start with

mrnutty 761 Senior Poster

Hahaha, none of our programs return.

int main(){

//return 0;
}

actually, it did, implicitly :)

mrnutty 761 Senior Poster

It checks to see if there is a string to check for anagram.

Since technically this check below :

if(str1.length() != str2.length())
return false;

could pass if both string is null;

So it checks to see if they are null;

Also I only need to check 1 string for null, since it will already
be determined that they both have the same length.

mrnutty 761 Senior Poster

1) Try rebuilding it.
2) How did you create this project?

mrnutty 761 Senior Poster

Give me an input values and what the output value supposed to be.

mrnutty 761 Senior Poster

Correction : Its
if(!str1[0])
return false;

and not
if(!str1)
return false;

mrnutty 761 Senior Poster

If you want fixed point then user

cout.setf(std::ios_base::fixed,std::ios_base::floatfield);

This will output number such as 1.2000000000 instead of
1.2e10

mrnutty 761 Senior Poster

strcpy(cline, sline.c_str());
chr = strtok(cline,",");
data.ticker +=string(chr);

You problem is probably there. whats sline.c_str() ? Its not
initialized to anything.

mrnutty 761 Senior Poster

Let the string class do all the work. use stringVariable.find() function.

Here is an example :

bool isAnagram(string& str1, string& str2)
{
	//check for length equality
	if(str1.length() != str2.length()) 
		return false;
	
	if(!str1) 
		return false;

	//check for string equality
	if(str1 == str2) return true;

	for(int i = 0; i < str1.length(); i++)
	{
		//search both ways

		if(str1.find(str2[i]) == string::npos)
			return false;
		if(str2.find(str1[i]) == string::npos) 
			return false;
	}

	return true;
}
mrnutty 761 Senior Poster

Go for class structure. It will definitely be a lot easier and less work,
as well as more elegant.

Here are some ideas :

class Hero{};
class BigHeadMonster { };
class Items { };
class Story { };
Class Map { };

Pick a class, start implementing it, and go from there.

mrnutty 761 Senior Poster

for(int i = 0; i <= Flowers; i++){

change that to i < Flowers.

Also notice the error : "application wrote to memory after end of
heap buffer"

It says that you wrote into memory where you were not
supposed to. If thats the case, then look in your code where
you write into heap, and most likely, thats where you will find
your problem.

mrnutty 761 Senior Poster

"So while cout.width() exists, I do not think there is much reason to
use it unless you really hate including <iomanip> for the parameterized
manipulators."

Its just easier for me to use cout.width, instead of including
iomanip, and using setw().

mrnutty 761 Senior Poster

rand() tries to simulate random numbers.

you can do this :

enum Direction {LEFT,RIGHT,UP,DOWN};
int getRandDir() { return rand()%4; }
int main()
{
   Direction curr_direction =    getRandDir()
  switch(curr_direction)
  {
    case LEFT : if(canMoveLeft) then moveLeft; break;
    case RIGHT : if(canMoveRight) then moveRight; break;
    // same for UP and DOWN 
   }
}

Of course you need someType of algorithm to get Robot to that destination

mrnutty 761 Senior Poster

if ( i % 10 == 0) continue;

mrnutty 761 Senior Poster

There is also cout.width(...).

mrnutty 761 Senior Poster

Somewhere you have declared a Item variable in your code.
maybe something like this : int Item;

mrnutty 761 Senior Poster

i++ or i+= will not work because the compiler doesnt allow such operations for enum iterations

what do you mean. Isn't 'i' a int variable declared inside the for loop?

mrnutty 761 Senior Poster

Look up linked list in google. Try implementing it that way, and
the push and pop should be easy to deal with.

mrnutty 761 Senior Poster

Oh silly rabbit, I forgot to seed the seed also.

mrnutty 761 Senior Poster

be careful no to have multiple base class. If so then use
virtual derivation.

mrnutty 761 Senior Poster

Something like this ? Don't know why you would wan't to do this
for.

for(int i = 0 ; i < 100; i++)
	{
		cout<<"Enter a seed value : ";
		int seed = 0;
		cin >> seed;
		while(seed < 0) { cout<<"\nEnter non negative number : "; cin >> seed; }
		cout<<"\nYour random number is  : "<<rand()<<endl;
	}
mrnutty 761 Senior Poster

thanks wild goose. Haven't worked with socket.

mrnutty 761 Senior Poster

try it.

mrnutty 761 Senior Poster

do you remember the formula for this project. It should be on your
handout.

mrnutty 761 Senior Poster

when I do

void filter(char* packet)
{

	for(int i = 0; i < 8; i++)
	{
		cout << "(" << int(*packet) << ")";
		packet++;
	}
		
	cout << endl;
}

It print's
(83)(65)(77)(80)(127)(0)(0)(1)
though, so that would mean the buffer contains that information right?

Thats weird. Try cout<<buffer before the function call , and in the function as well. See if they are the same.

mrnutty 761 Senior Poster

"will evaluate to false when packet==0"

Yes thats correct. The 0 identifies the end of the string. Any further
then its junk.

mrnutty 761 Senior Poster

Then your problem is the buffer thats being passed to it. I does
not contain what you want.

I assume that the problem is here:

bytesReceived = recvfrom(incs.cl, buffer, 1024, 0, (struct sockaddr *)&clSockAddr, &fromlen);

Check if bytesReceived is the correct number of bytes you want to recieve.

mrnutty 761 Senior Poster
void filter(char* packet)
{
    int i = 0;
	while(packet[i])
	{
		cout << "(" << int(packet[i]) << ")";
		i++;
	}	
	cout << endl;
}
mrnutty 761 Senior Poster

You know C++ is a MAJOR step above C.

mrnutty 761 Senior Poster

Is the string a char of digits or characters?

mrnutty 761 Senior Poster
//open a file for for reading and writin
ofstream oFile("outputFile.txt");
ifstream iFile("inputFile.txt");
char c;
std::string str;
while(iFile.get(c)) { str +=c; } //read in data

//now write into the output file
mrnutty 761 Senior Poster

If I am reading correctly, you want to show packet as an int, via this
function?

void filter(char* packet)
{
	while(*packet != 0)
	{
		cout << "(" << int(*packet) << ")";
		packet++;
	}	
	cout << endl;
}
mrnutty 761 Senior Poster

Look at std::vectors. They are dynamic sized array
capable of being 1d,2d,3d , 4d...

And used that with openGL, a graphics library for any 2d or 3d or
even 4d objects.

mrnutty 761 Senior Poster

"m*m =i "

Lets see , let m = 5, then

5 * 5 = i
---------------
5 * 5 = 0  /// 25 = 0  // = false
5 * 5 = 1;// 25 = 1 // false
5 * 5 = 2;// 25 = 2 // false
5 * 5 = 3//25 = 3 //false
// so on until i = 25, then it would be true, but has no effect on the 
loop

Did that make sense? Obviously m*m =i , is not what you
want to do. I think you are looking for is what wildgoose posted.

mrnutty 761 Senior Poster

"At what point did I say I was a guy? I've learn't C++ when I was
about 14, and started C a few month's ago (maybe 10)."

Why would you want to learn C after learning C++?

mrnutty 761 Senior Poster

use a for loop.

mrnutty 761 Senior Poster

const unsigned int MAX = 25;
BaseClass * pBC[MAX];

Make sure BaseClass has some virtual function if needed.

Now you can static bind or dynamic bind.

Static Bind :
pBC[0] = new BaseClass
pBC[1] = new InherietFromBaseClass
//and so on

Dynamic binding
cout<<"1 for baseclass, 2 for InherietFromBaseClass, //and so on";
int opt = 0;
cin >> opt;
if(opt == 1) pBC[0] = new BaseClass
//and so on
mrnutty 761 Senior Poster

This might be of help. Much easier way of reversing a string.

//note using mathematical notation its  [strt,end] and not [strt,end).
//strt is included and end is included as well.

void reverseRecursivly(string& str,int strt, int end)
{
	if(strt >= end || !str[0]) return;
	
	std::swap(str[strt],str[end]);
	reverseRecursivly(str,strt+1,end-1);
}

And also your makeUpper function is wrong :

string makeUpper(string s) {

	for (int i=0; i<(int)s.length(); i++) {
		if ( islower(s[i]) ) {
			s[i] = toupper(s[i]); //Revised
		}
	}

	return s;
}
mrnutty 761 Senior Poster

Hey thanks Laiq. ++Reps to you.

mrnutty 761 Senior Poster

To convert decimal value to percentage you divide a value by
its max attainable value. For interest if user inputs 6 percent, the
max percent attainable is 100, so we divide 6 by 100 to get the
percentage.
Also

if (interest <= 0) {
		cout << "Please enter a valid Interest Rate";
		cin >> interest;
 
	}

You might want to make that a while loop, so until the user enters
a correct value, he gets prompted.

mrnutty 761 Senior Poster

Forget it. I though you were doing animation where
the user specifies the starting and ending position of the robot,
and you simulate it.

mrnutty 761 Senior Poster

"Also, I've been trying to research how to hop out of a function when a
condition is met"

if(condition is met) return false; //assuming function is bool returned typed

int main()
 {

while(Alive)
   {
     if( checkConditionIsMet() == false) return out of this function.
   //some stuff
   }

}
mrnutty 761 Senior Poster

I mean no matter how bad your teacher is, he/she wouldn't be hired if they weren't capable of give AT LEAST the basic knowledge of programming and where to start.

True, but that doesn't necessarily mean that he has good
programming habits.

mrnutty 761 Senior Poster

I would help, but I think I just got blind.

Seriously, whats part a and b?

mrnutty 761 Senior Poster

Post your whole current code

mrnutty 761 Senior Poster

"I have heard the horror stories of terrible hours and bad job security
in game programming."

Its nothing compared to the joy one gets when making games (not to be Cliché).