"This 2 pieces of code is equal"
well mostly the initializer list is more optimal than the second way.
"This 2 pieces of code is equal"
well mostly the initializer list is more optimal than the second way.
I think this is supposed to be a recursive pow() function.
.
glut/opengl/c++ is easy to start with
Hahaha, none of our programs return.
int main(){ //return 0; }
actually, it did, implicitly :)
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.
1) Try rebuilding it.
2) How did you create this project?
Give me an input values and what the output value supposed to be.
Correction : Its
if(!str1[0])
return false;
and not
if(!str1)
return false;
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
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.
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;
}
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.
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.
"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().
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
if ( i % 10 == 0) continue;
There is also cout.width(...).
Somewhere you have declared a Item variable in your code.
maybe something like this : int Item;
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?
Look up linked list in google. Try implementing it that way, and
the push and pop should be easy to deal with.
Oh silly rabbit, I forgot to seed the seed also.
be careful no to have multiple base class. If so then use
virtual derivation.
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;
}
thanks wild goose. Haven't worked with socket.
try it.
do you remember the formula for this project. It should be on your
handout.
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.
"will evaluate to false when packet==0"
Yes thats correct. The 0 identifies the end of the string. Any further
then its junk.
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.
void filter(char* packet)
{
int i = 0;
while(packet[i])
{
cout << "(" << int(packet[i]) << ")";
i++;
}
cout << endl;
}
You know C++ is a MAJOR step above C.
Is the string a char of digits or characters?
//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
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;
}
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.
"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.
"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++?
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
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;
}
Hey thanks Laiq. ++Reps to you.
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.
Forget it. I though you were doing animation where
the user specifies the starting and ending position of the robot,
and you simulate it.
"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
}
}
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.
I would help, but I think I just got blind.
Seriously, whats part a and b?
Post your whole current code
"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é).