pseudorandom21 166 Practically a Posting Shark

Most of the features you want are probably available via the operating system API, I'll assume you're using Windows so here's the API ref.

http://msdn.microsoft.com/en-us/library/ff818516(v=vs.85).aspx

of course you don't have to roll your own, there is plenty of code available for random stuff.
http://www.codeproject.com/KB/cpp/AddColorConsole.aspx

otherwise here's the console link:
http://msdn.microsoft.com/en-us/library/ms682087(v=VS.85).aspx

That codeproject lib looks like a good one because it implements changing text colors as some stream manipulators.

Agouri commented: Helpful links in my C++ help thread +0
pseudorandom21 166 Practically a Posting Shark

Please see the link to the youtube video in my signature.

If you can stand my voice and horrible narrating it will show you one of the best ways to figure out a problem like that, assuming you're using Visual Studio.

Also if you're copying a project you may want to make a blank project, then copy and paste the files you want to work with into the new empty project's directory (Documents/VS2008/projects usually), then in the IDE, right click on the project name and select "add existing item" to add them to the new "solution"/project.

pseudorandom21 166 Practically a Posting Shark

Yeah actually on Visual Studio 2010 the option is still there, it's under the

project properties -> C/C++ -> Language

tab.

pseudorandom21 166 Practically a Posting Shark

Yes the variables you initialize in the body of the for-loop are local to the loop body's enclosing scope. I think that's written somewhere or something.

In older implementations of C++ that was actually an option for Microsoft's compiler, probably even Version 6.0 of it. Heck there may still be an option to make the variables persist.

pseudorandom21 166 Practically a Posting Shark

I think it would make more sense as a for-loop.
Also the creation of a function to determine whether it's a yes or no would probably simplify things.

Sadly since you've said you can only use certain features of the language then your answer will probably suck.

Perhaps this will help:

bool GetAnswerResult(string answer)
{
	//if you must list every acceptable answer
	//why not use const strings?
	const string falseOne = "n";
	const string falseTwo = "N";
	const string falseThree = "No";
	const string falseFour = "NO";
	const string falseFive = "nO";
	//Work your magic here.
}

int filler (Book single[], const int s)
{
	string ans;

	for(int i = 0; i < s; i++)
	{
		single[i]=getitems();
		cout<<"Would you like to enter another book?(y/n)";
		cin >> ans;
		if( !GetAnswerResult(ans) )
			break;
	}
	return i;
}

Also, your naming system seems a bit flakey.
Pick a style and stick with it until you know better.

I still say use the first character of the y/n answer to determine the result.

pseudorandom21 166 Practically a Posting Shark

Post your code inside the code tags: [code] /* CODE HERE */ [/code]

Also, please preserve the formatting (posting in the code tags will do that). You will need to copy it from it's original source again.


Here's a tip for your "filler" function though,
read a line of input at a time and extract (parse) what you need from it.
The reason to do so is to avoid causing "cin" to fail and have junk left in the input buffer because the process of clearing the buffer and ignoring the garbage is different from platform to platform.
It's much easier to do this:

string inputLine;
getline(cin,inputLine);
if(inputLine.size() == 0)
   return;
char answer = inputLine[0];

Also there are useful character functions in <cctype> like "toupper" and "tolower".

string inputLine;
getline(cin,inputLine);
if(inputLine.size() == 0)
   return;
char answer = toupper(inputLine[0]);
if( answer != 'Y' )
   return;
pseudorandom21 166 Practically a Posting Shark

I am indeed using linux and I may give a try to your idea but I'd like my code to be as portable as possible.

So, I'd like to find another solution!

Thanks for the hint...

oooh sorry link fail!
lol, it was supposed to be a youtube video.
http://www.youtube.com/watch?v=ys4NjnSyzkY

pseudorandom21 166 Practically a Posting Shark

Hey if you're using linux why not give the C++0X threads a try?
http://www.cnn.com/video/?/video/cvplive/cvpstream1

I don't know how to use the pthreads library or I would be able to help more, sorry :(

pseudorandom21 166 Practically a Posting Shark

The dox also say it's used to add events to the queue, so after you process one in main I suppose you can put it back on the queue...
Not sure how that will pan out though.

pseudorandom21 166 Practically a Posting Shark

SDL_PollEvent returns 0 when no events are left to process, perhaps this happens more often than you realize?

Also the nature of polling implies if you wait too long between polls (doing work in your switch) you may miss something.

pseudorandom21 166 Practically a Posting Shark

Yes you can:

1)
Write the "move" function so that it operates properly using the "WARRIOR" information.
ex:

const std::string WARRIOR = "Warrior";

class Character
{
public:
std::string Type;
void move()
{
   if(this->Type == WARRIOR)
     ;//move
}
};

2)
Redesign using polymorphism with a base class and a Warrior derived from it.
ex:

class CharacterBase
{
public:
virtual void move() = 0;//Pure virtual
};

class Warrior : public CharacterBase
{
public:
virtual void move()
{
   //Move your warrior.
}
};

void MoveCharacter(CharacterBase *myChar)
{
   myChar->move();
}

int main()
{
  Warrior myKnight;
  MoveCharacter(&myKnight);
}

3)
Use a function pointer or functor.
ex)

typedef void (*MoveFunc)(void);// named type for my func. pointer

void MoveWarrior()
{
   //etc.
}

class Warrior //redundant, etc.
{
  MoveFunc moveFunction;
  public:
    void move()
    {
      moveFunction = MoveWarrior;
      moveFunction();
    }
};

Please excuse minor bugs.
Also, there are a large number of other strange things you can do with C++ so you're pretty well-off on finding a way to do it.

pseudorandom21 166 Practically a Posting Shark

I'm not sure I entirely understand your question.

You would like to define a string constant, correct? const char *WARRIOR = "Warrior"; -or- const string WARRIOR = "Warrior";

void play(char gameWorld[][BOARD_SIZE])
{
	Warrior war(1,1);
	int userChoice = getUserChoice();
	string currentPlayer = WARRIOR;

	while(userChoice != 'q')
	{
		switch(userChoice)//<--
		{
		case(50): //<-- what?
((string)currentPlayer).moveDirection(DOWN);
		}
		userChoice=getUserChoice();
	}
}

The "switch" is a cleverly disguised specialized if/elseif, and it's fairly primitive. You might find it easier to use if/elseif/else.

pseudorandom21 166 Practically a Posting Shark

I bought a book on C# and read most of it one day, the knowledge seemed to sort of sink in once I wanted to use C# for some small projects.

pseudorandom21 166 Practically a Posting Shark

//Also you shouldn't use "exit" in a C++ program, because it may cause destructors to not be called.
This probably isn't true anymore, but normally it isn't excusable to use exit() anywhere except the main function, instead you might want to throw an exception and then the caller can elect to handle it, or not (terminate the program).


"endl" does more than insert a newline, it also flushes the buffer. If you need to optimize such a trivial program, well.. There must be something unseen happening.

If you just want it to be easier to work with declare constants for array sizes and decompose it into more functions.

pseudorandom21 166 Practically a Posting Shark

Change endl to "\n" and work on your indentation instead of optimization.

pseudorandom21 166 Practically a Posting Shark

it should accumulate and print the spaces all at once instead of one at a time.

pseudorandom21 166 Practically a Posting Shark

I think it's asking you to fix the loop such that it doesn't print multiple spaces here:

// are we on the border?
                if (r == 0 || r == rows - 1 ||
                    c == 0 || c == cols - 1)
                    cout << "*";
                else
                    cout << " ";
pseudorandom21 166 Practically a Posting Shark
std::string buffer;
std::getline(std::cin,buffer);
pseudorandom21 166 Practically a Posting Shark

you check the least significant bit to determine if it's even or odd, because it's 2^0 = 1.

thus you can shift the bits the proper direction and determine if the bit is set or not.

in case bits were never described this way to you:
[ ] [ ] [ ] [ ]
we have four bits here, each with a value of:
[2^3] [2^2] [2^1] [2^0]

least sig. bit is set? value = 1.
lest sig. and 2^1 = 3.

for a byte this continues to 2^7.

pseudorandom21 166 Practically a Posting Shark

I think there are plenty of solutions here, I hope the thread owner closes this thread soon or tells us about a problem.

JOSheaIV commented: He helped me threw this problem alot (and since it will be awhile before I could get back to it I decided to answer it solved and give this guy some Kudos for it) +3
pseudorandom21 166 Practically a Posting Shark

iv coded it for ppl convenience.. u can check

No you haven't, you didn't indent it properly or your paste got messed up by not using the code tags and then you copied the unformatted text and pasted it into the code tags.

Usually people on help forums have a difficult time helping people that post a whole class and expect us to debug it for them, so tell us, what do you think is wrong with it?

I would ask you to look into the debugging features of your current compiler/ide toolkit.

pseudorandom21 166 Practically a Posting Shark

Taken from:
http://stackoverflow.com/questions/937573/changing-the-useragent-of-the-webbrowser-control-winforms-c

You could try: webBrowser.Navigate("http://localhost/run.php", null, null, "User-Agent: Here Put The User Agent"); Or another of the solutions there.

I just tested that on "http://www.whatbrowseramiusing.co/", it reported "unknown user-agent" but the idea is to use one that is known, like chrome's user-agent or firefawks'.

pseudorandom21 166 Practically a Posting Shark

Lame!
I just watched something on the news about the iPhone versions, and I was just thinking "if steve jobs is watching this he would be happy". It seemed to be very Apple-oriented.

pseudorandom21 166 Practically a Posting Shark

There are tons of specialization areas for programmers, you could look into artificial intelligence, or automation to name a couple.

I don't feel this list is complete,
http://www.bibl.u-szeged.hu/afik/compw.html

pseudorandom21 166 Practically a Posting Shark

Yes, I made a website scraping app in C++ once, the "browser" is supposed to send a tag identifying it's self, and as such you can likely fool the website by altering your "user-agent" string.

Oh luckily there is a UserAgent property for the class (woo!)

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent.aspx

I don't know much more about it, but MSDN also says that class is obsoleted.

pseudorandom21 166 Practically a Posting Shark

If you're using visual studio check the youtube link in my signature to learn to use VS debugging features.

pseudorandom21 166 Practically a Posting Shark

If it's any help I usually tend to use the WebBrowser control for these things, and use the "DocumentCompleted" event handler to work with the read the "Document" property of the WebBrowser.

pseudorandom21 166 Practically a Posting Shark

totnum[20]/x; That line accesses an element of the array that doesn't exist, it's one past the end of the array because the array is size 20 and indices start at 0.

Also, when you use the subscript operator "[ ]" on the array, you're accessing only one element. You'll need to loop through each element of the array (up to the num. of test items) and add them together, then divide by the number of test items.

pseudorandom21 166 Practically a Posting Shark

There is NOT a NULL in that array!

pseudorandom21 166 Practically a Posting Shark
pseudorandom21 166 Practically a Posting Shark

I wrote a function that finds the lowest numeric grade score of the pointer array of struct, puts it in the first (0) index position, and then puts the numeric value that was in the first (0) index position in the index position that was formerly occupied by the newly found lowest value.

[3][2][1][0]
[0][2][1][3]
...

Then, it starts at the next highest index position and finds the next lowest value, etc, and swaps it.

[3][2][1][0]
[0][2][1][3]
[0][1][2][3]

So it appears to be algorithmically sound assuming you implement it properly :)

The issue that I'm having is that I can get the numeric scores sorted properly and moved in the function, but I can't get the first and last names in the array to change position, except somewhat unpredictably.

The best advice I have for you is to run your code under a debugger and see for yourself what is happening. If you're using Visual Studio be sure to "start debugging" and set some breakpoints to examine the contents of your variables.
If you don't know what I mean I will make a youtube video of it and link you to it, but who knows when that will be.

pseudorandom21 166 Practically a Posting Shark

"std" is a namespace and it is short for "standard".

If you don't include "using namespace std;" then you have to do this:

#include <iostream>
int main(){
std::cout << "Notice the namespace followed by the scope resolution operator?" << std::endl;
}
pseudorandom21 166 Practically a Posting Shark

Likely on your system there is also a Windows Media Player class.

pseudorandom21 166 Practically a Posting Shark

If you post in the C++ forum I'll help you, as will others.

pseudorandom21 166 Practically a Posting Shark

Maybe it's throwing an exception you didn't catch?

pseudorandom21 166 Practically a Posting Shark

What I want to do is have a predefined battle function, I can code the function, all I need to know how to do is have the function sitting there, so when I call it, all it takes is one or two variables to set up and go. So every time I don't have to input damage calculators, defense algorithms etc.
Help would be greatly appreciated, thanks.

Wut?
I don't think we have enough information to help you to a great extent, but you may look into passing by value and passing reference, as well as passing arrays and pointers.

pseudorandom21 166 Practically a Posting Shark

as far as I know you can't name a variable starting with a number.

try clearing the error bits before opening a new file with a previous fstream.

i.e.,

//...
file01.close();
file01.clear();
file01.open("...");
//...
pseudorandom21 166 Practically a Posting Shark

don't use "01" and "02" as variable names.

Your IDE may have a handy find & replace feature to let you quickly change it too,
try hitting Ctrl + F.

pseudorandom21 166 Practically a Posting Shark

If a file fails to open or an error bit gets set (like EOF) then you have to clear them before opening a new one.

pseudorandom21 166 Practically a Posting Shark

I've been programming in C++ for quite some time now and I know all functions must return a value.. but can someone tell me WHY we return 0?

I mean it compiles even when I don't put return 0.. and the program executes fine.. I can see in some functions we'd return a variable or a value.. but for int main() why do we always have to write return 0? Someone told me its the new standard that we don't have to type it anymore but I'm so used to return 0 that I can't not type it. I also heard its because when a function returns a value other than 0, it means something is wrong and the operating system can check the value it returned and check for memory leaks or something..

what if I returned 256? it still works.. :c

also can someone explain when i use unsigned variables?? I never use them unless a function on MSDN requires it.. so is there any use of them other than passing them to functions as parameters? Oh and when do we use constants? I mean I can just use a float or integer instead of const int or const float.. just don't change the value right? When do we use constants :S

I saw someone do this:

const float PI = 3.14159265f;
const float DEGREE_TO_RADIAN_FACTOR = 0.0174532925f;

can someone explain why there is an "f" at the end of the values??

Thanks in advance.

Yep.

but can someone tell …

pseudorandom21 166 Practically a Posting Shark
pseudorandom21 166 Practically a Posting Shark

1. In a for or while loop, if the condition is breached in the middle of the brackets {}, will the code immediately stop the loop, or wait until it gets to the bottom of the brackets {} ?

2. If a function is called in my code, does the computer wait until the function is finished before continuing with the rest of the code?

#1. Wait until it gets to the bottom, it will.

#2. Yes it does.

pseudorandom21 166 Practically a Posting Shark

I also don't think fstream will have a problem with 4+GB files, I think sadsdw's problem is more likely due to memory usage (speaking from experience).

pseudorandom21 166 Practically a Posting Shark

How is your weather in your country? I am living in the Philippines and the weather here today is stormy and according to news, we are overloaded of typhoons in this month. One typhoon is over and there is 2 more waiting on the line. Oh boy!

I wish it was like that here, it's just really hot and humid too. It sucks.

pseudorandom21 166 Practically a Posting Shark

Most of these so called shooters release some extremist bit of propaganda to go along with their act of violence.

I guess it gives them a twisted way to justify what they've done. But if you look closely... most of the reasons are just plain old baloney.

'The reason I am going to shoot up a whole load of people is because 'insert___extremist___rhetoric___here.'

The reason why most these individuals do these things is because they just suck at life... Compounded with clear psychiatric problems, because NO sane individual would shoot up a load of people, this is just like a time bomb waiting to go off.

Unfortunately, with no real psychiatric support and continued rejection in an area of life they clearly suck at, these individuals begin a downward spiral into oblivion.

The sad thing is, all it may have taken, was someone to grab this guy by the scruff of his neck when he was sucking at whatever he was bad at life, shown him how to do it properly... and a few successes later he'd be a normal, happy everyday citizen.

You might shoot up a bunch of people if they were about to become human-flesh-eating zombies.

pseudorandom21 166 Practically a Posting Shark
#include <time.h>
time_t whatTime(const char* month, const char* day, const char* year)
{
    time_t rawTime;
    time(&rawTime);
    struct tm* convTime = localtime(&rawTime);
    std::cout << "Today is: " << ((convTime->tm_mon)+1) << "/"
                              << convTime->tm_mday << "/"
                              << convTime->tm_year << std::endl;
}

When using this code I get the output '7/27/111'
Why does the year appear as 111 instead of 11?

tm::tm_year is the number of years since 1900, which is 111.

pseudorandom21 166 Practically a Posting Shark

I enter u and it stringstreams that. I don't know why but the number comes out very large and if the number isnt greater than -999999999 then run the default numbers. When i enter u, its supposed to use the default number in the text file. And uc changes that default number.I'll add functions and see if it works. Does anyone know how to detect if an inputed string is not a number?

Sorry could you explain that in better English? Basically I'm wondering what: "greater than" "logical not" means.

pseudorandom21 166 Practically a Posting Shark

I do believe there are things worth dying for, but the dude is obviously in the wrong. You don't just kill people to promote a book! Unless the book is going to save the world, but somehow I doubt that if we don't read it the world will split in half and shoot demons from it's core (hey that might be a cool book).

Shooter = Crazy.

pseudorandom21 166 Practically a Posting Shark

What exactly does this do? if(ff1 >! -999999999)

pseudorandom21 166 Practically a Posting Shark

I've found that the math function "y = (x^2)/n" is easy to work with, assume n is the height and width of the window (they need to be the same) and the curve (parabola) the function produces will pass through (0,0) and the upper-right-most coordinate of the viewing window.

So then you have a function to make a parabola that looks like this with a defined height and width (see attachment).

otherwise it's much more complicated, I used this graph for mouse sensitivity in a project. If you knew the math you could use an expression parsing library to find the functions for curves that pass through specific points.

http://www.codeproject.com/KB/recipes/FastMathParser.aspx#idExample

sergent commented: :) +4