jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Peter is an actor, I believe.

The answer's on Wikipedia (WaltP, you shouldn't trust that this generation of trivia buffs won't look lol) I won't spoil it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Say you had:

enum priorities {zero,one,two,three};
priorities mypr;
int i = 4;
mypr = static_cast<priorities>(i);

What does mypr then mean? There's no value in the enum for 4, so should it be cast to 4? It's saying that this behavior could cause almost any results and should be avoided.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Or attempt a design where it is created in main() and passed into the functions that require it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That is true.

Also check the number of bytes a short int occupies on your machine (using sizeof). Mine is 2 bytes. Since short is signed so you only get half of the range. The maximum in that case is 32767. You're way over that from the get-go on line 7.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

#include <ctime> and call srand((unsigned)time(0)); (once) before you call rand().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You modified the code correctly. I probably should have worded what I said a bit differently. The "offset" is actually part of the Taylor series yielding an approximation around that certain point a. The series you had programmed is around a = 0, which collapsed all of the x-a terms into x (see the first line under the http://en.wikipedia.org/wiki/Taylor_series#Definition heading), so I was merely saying put the x-a terms back in where they belonged. Having done that you could re-evaluate for increasing a.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See this for a reference. The way you are expressing e^x is for the Taylor series centered around 0. There is a corrective factor of -a (so you substitute x-a for x in your equation) to get a better approximation for the series centered around a. I'm not sure how often you'd have to recalculate it to keep the accuracy up.
You're assuming that the cmath function uses a plain Taylor series about zero but there are probably better approximations out there.

EDIT: Further probing got me that the library probably uses minimax polynomials rather than the Taylor series. See http://mathworld.wolfram.com/EllipticRationalFunction.html and its related articles if you're interested. Otherwise I can't think of any way to make your Taylor series more accurate other than to recalculate it with a new center spaced at +10 from the prior center (that's just my own speculation I don't know if the theory supports it).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't have to, just giving you the proper credit and verifying that I didn't lie there in wait for you to post and immediately copy what you said. Or it's a bad habit I picked up. Your choice :D

WaltP commented: I'll take it as a bad habit :-) +9
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

while(!input.eof()) See this about eof.

Your function is passing in avg by reference but never doing anything with it. Either return your (S1+S2)/2 calculation and use it as such or make the function void and assign ave = (S1+S2)/2;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Either make choice a single character and acquire it by cin.get(choice); (you will need a cin.ignore() after to mop up the '\n'
or use if(strcmp(choice,"Y") ==0) instead of your (choice == "Y") EDIT: D'OH WaltP beat me to it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thanks DS. Can't say I didn't drop the ball on that one. I guess I could say I was going for an overall Gestalt.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try itoa. It's not standard so there may be portability issues but I think most implementations have it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome. So what have to tried so far?

It might be easier if you posted 1-2 lines of your text file since it's sometimes tough to assimilate the information in the abstract.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can either make them static or have a constructor with an initialization list

struct Budget 
{
  static double housing;
};

double Budget::housing = 500.00;

-or-
with the constructor

struct Budget 
{
  double housing,       //Housing payment variable
     utl,               //Utitlities payment variable
     houseExp;         //household expenses payment variable

    Budget() : housing(500.00),utl(50.00),houseExp(150.00)  {}
};

As far as your other if/else situation goes, there are probably some interesting ways to do it like with 3 parallel arrays that hold the category name, the standard amount, and the actual amount. The standard - actual calculation could be placed into a fourth array compared to zero and the categories in excess and deficit printed off.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am concerned on how to get the variables directly in the structure

Can you give an example (or more details) about what this means?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to use DateTime.ParseExact() -- http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx along with the the format specifiers on this page.

I tried to get it to work but it was fighting me on the GMT specifier. However, if you move the date to right after the month it will match the built in "R" specifier and you can read it with DateTime.Parse("R");

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You shouldn't repeat all those calculations over and over in each branch of the if statements.
Do the common calculations, have an if statement that changes any values that are uncommon to the set, then proceed with the next set of common calculations for the group, etc.

Also, you should pass in arrays, structs, or vectors of your parameters to your gauss function to clean up the sheer volume of values. It's just a lot to have to put in there and once you get beyond 4-5 parameters it starts to make your head spin.

Other than that, seems to be ok but I didn't put it under a microscope. Keep plugging away at those numerical methods! :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also, why are you trying to read 257 characters into the 256 char array? (that would be valid if you had indexes 0 through 256 but you only have up to 255)

A brief mea culpa: You are partially right. The get() function leaves room for the terminating null, so only gets n-1 characters, but your array has to be that size n as well. That's why you were getting 15 chars you need an array that holds 17 chars to get 16.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This should be an indispensable reference for you. You ought to be able to dig up code for most if not all of them (at least the *nix ones).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of the problem is you are trying to read a text file in binary mode. In binary mode you need to use read() to get a block of bytes. I can see how it might read some of the chars in that way but there must be some subtlety that is goofing it up. I would omit the ios::binary and see if that improves things.

Also, why are you trying to read 257 characters into the 256 char array? (that would be valid if you had indexes 0 through 256 but you only have up to 255)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
stringstream ss;
ss <<"Hello"; //send this into the stringstream
cout << ss;    //gives the address of ss
cout <<ss.str();  //gives "Hello"
string mystr = ss.str();
then mystr.c_str() is "Hello\0"

so with ss.str().c_str() we're first taking the stringstream object and using it's str() method to access the string, which we're then calling the c_str() method of that string to get the null terminated one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use a stringstream:

#include <sstream>
.....
stringstream ss;
cout <<"Enter store no.:";
cin >> number;
ss <<"Store "<<number;

Then use ss.str() to get the std::string version and ss.str().c_str() to get the c string version for strcmp.
There's probably a different approach that would work but I think this is the most intuitive (for your insert method to work you'd still need the integer as a string).

As far as the adaptability of your code to larger lists it should be fine. Try it out, add some more stores into the file. Add some "junk" in there to throw it off.
The code that VernonDozier gave you should be robust to these changing file size situations (he used the eof because it's fairly certain that your store number won't be the last or second to last line in a valid file). You could use getline to drive your while loop if you were concerned about running into the end of your file. So:

(if infile is your ifstream and chararray is an array of char,40 chars in length)
while(infile.getline(chararray,40)  //#40 so you can store the address ok
{
      if(strcmp( ...etc
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
while (! input.eof())
	{
		// Read names from file using ',' for delimiter?
		getline(input, Names[rTotal]);
		
		input >> Names[rTotal];

		input.ignore();

		++rTotal;
	}

This was overwriting the name you read in with the getline immediately after.

You want something like:

rTotal = 0;
while(getline(input,rTotal))  //uses default delimiter of '\n'
{
     rTotal++;   //can omit the braces if you want
}

which uses the state of the object returned from getline to drive the loop (nothing to read in -> 0, a null address, is returned, loop quits). This reads in your last, first into one string so now you can sort and search (btw, sorry if I gave you an aversion to the binary search in that other thread)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do they have the VC++ 2008 Redistributable installed? See this article.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You represent strings just fine elsewhere in the same program, what happened with these two?

while((guess != theWord) &&(guess != 'quit'))
{
     if (guess == 'hint')
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm embarrassed because I thought I had tested it. It turns out that it's trickling down from the cin >> fileName call. Put the cin.ignore() immediately after that line (13 I think*) and take the other one out. I wish I'd seen it before.

*also please use the code tags on your post (that would give the line numbers and keep the formatting):

[code]

//code goes here

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yup, you got it. No problem!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, so you have a mean now, but you're still not applying the pow stuff right. Again look at the theory, you are averaging the amount of variation of each point from the mean, squared and taking the square root of it. So it's going to be pow(x1-x,2)+pow(x2-x,2) + etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use the iterator approach but this time if it->second equals the value you want, report it->first as the key. I don't think there's a built in way to search for key by value (you can probably find containers people have written-- like 2-way dictionaries -- out there).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check your "namspace" line. Also include <string> for std::string, not <string.h> (string.h has strcpy, strcmp etc stuff for C-strings). That's what I get at a glance, there may be more.

And yes, you should post your error messages as we should not be your compiling service.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Start out with something like this (it has good examples for you). Google any terms you don't know and when you have something you're stuck on, post back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change line 11 to: string get() const //get name . I think it stems from the nature of the strings once they enter in the map (since they become keys) but I am not sure.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

or system("clear"); on *nix computers.

system is used to run a command of either dos or *nix on the respective system. He was offering you system("cls") on your Windows baed PC or system("clear") for use in *nix if it was applicable.

However, AD was also saying that this information is not even relevant to your task at hand because this is simply a solution to wipe the console clean of any output and it does nothing to any of your inputs that you are asking how to clear.

Salem was simply saying that we really don't know what you are trying to do so we cannot help without more specifics. If all you want is a keypress to keep something going just throw away the key or never save it in the first place a la getchar() with no lvalue.

(sorry to speak for anyone if they didn't intend it like that)

Ancient Dragon commented: Exactly right :) +26
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I tossed in a bit of pseudocode there to make sure I didn't have all the fun. I'm sure there are more compact and elegant ways of doing it, but basically you march through the array looking for the first colon. When it's found you put up a flag saying ok I've found one colon. Keep marching until another colon is found. If it's the second colon, break out of the for loop and record the index.

Now, from what you are saying, the best thing to do would be to read the string up to the second colon like I said earlier, copy everything up to and including that position into a new buffer that is bigger than the first by the number of digits you want to insert.
Copy over your new digits, and finally copy from the / to the end of the buffer into the new one. You can definitely use strcpy, strncpy, etc if you want to also.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.ignore(); right before your getchar() call. There is probably something left over in the input stream after your getline call (though I think getline should discard the newline but maybe I'm thinking of something else) which is taken in by your getchar ending the first pause.

Another thing to watch out for is your use of !file.eof. Take a look at this thread for an explanation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would search for the second instance of the colon,

int pos;
bool found = false;
for(over the buffer)
        if (found && buff[i] == ':' )
        {
                 pos = i;
                 break;
         }
        else if(buff[i] ==':')
               found = true;
         etc.

march up until the / to get the digits length (or if you already know it skip this step) make sure the value you are inserting is the same number of digits and just write them into the array directly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need to use rand/srand if you do what AD showed you. The algorithm takes care of that for itself.

If you want to use the approach you propose there, just do i = rand() % QA; (which will get you a random number between 0 and 9)and cout question.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

getAverage(array[].4.5) is not correct. When passing in a 2D array only the last dimension is needed, so it would be getAverage(int array[][5]) in the function definition.
Make life easier on yourself and use a nested for loop approach to the averaging function:

for (int i = 0;  etc        )
     for(int j = 0; etc)
              add to running total array[i][j]

So hint, for the function using one row of that you'd still pass in the array the same as the average function but loop through holding i constant (set i to something and then run through the j's values).

The others looked ok but that doesn't mean I didn't miss something.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm assuming x1 thru x5 are your data points?

The definition of the standard deviation involves first finding the mean of the values.
Then find the variance by summing (the difference between data point i and the mean)^2 divided by either the number of values (for an entire population) or number of values - 1 for a sample.
What constitutes a population is debatable and so you probably have a sample.
Taking the square root of the variance gets you the standard deviation.

Some p-code:

double total;
for loop to find the total of the data points

double average = total/ 5;
double totaldev;

for loop over the data points again
      totaldev += pow((data i - average),2);

sDev = sqrt(totaldev/4);

(obviously I've hardcoded the N values based on the number of parameters you pass in)
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It couldn't hurt to do a search at the VS express editions install forum. I don't know the answer to your question but they get asked this kind of thing on a daily basis.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are a couple of things that are standing in the way of this compiling.
When you posted last I assumed incorrectly that this would be a console application. Upon a closer look it appears to be an MFC (MS Foundation Classes) application which is not directly supported by the express edition of VC++ only the standard.
In addition to that, the project seems to be missing some of the components, in particular the dialog resources (to what extent they can be regenerated I'm not sure).
That error message you were getting was coded into one of the header files to make sure that stdafx.h was included before that particular header file. In the stdafx.h that I generated with a Win32 project in VC++ express that value was not defined, which again may be a result of needing MFC, but I am not 100% on that.

Others more steeped in MFC might be able to advise you on how you can finagle this code back into Win32 or might be able to suggest a means through which you can access the serial port with the API.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try branching off from your 3 of a kind method?

bool FullHouse;
if (Hand.Card[4].iValue == Hand.Card[3].iValue && Hand.Card[4].iValue == Hand.Card[2].iValue)
{    
      if(Hand.Card[1].iValue == Hand.Card[5].iValue)
             FullHouse = true;
      else
      ThreeOfAKindCard = Hand.Card[4];
}
else if (...) etc.

I know it doesn't combine your pairs check with the three of a kind but if you don't "sequester" the three of a kind cards they'd be counted by the pair finder too. A solution would be to have a pair finding function that you could call both for both finding the pairs and finding the full house.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your function signatures should look like the following:

double getAvg(school &, int);
string getGrade(school &, double);

You turned average into a double which was the right thing to do (but see below) but your function was still returning an int. Why you are getting the weird amount (and no grade) was because you need to pass school in by reference to these 2 functions also (since you are modifying student within the method). I did give you a partial glimpse of this back in post #3.

Since total and 4 are integers, essentially what student.average = total /4; does is do the integer arithmetic (with truncation) and then assigns it to the double as such. You need to cast total (or write 4 as 4.0, or both), so student.average = ((double)total)/4.0; will do the trick (I know there are extra parens but just for clarity)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Flip back (or forward) a chapter or check out this.

Essentially using one kind or another determines the access (public, private, or protected) of the data members in the derived class based on their respective access types in the parent class.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

pare down your code to the strings

it will even flag scanf, printf, struct etc as errors.

That's why I was saying to pare it down (strip off the other stuff and just leave the strings). You could grab text from "(quote) to "(quote) and hang on to that so you'd end up with something like:

(Line #)
   17 -- The quick brown fox
   19 -- Enter a number: 
  201-- The net annual sales are

Spell check it, write it out as text from the WP, merge it in as you see fit.

I will grant you it's a tedious and roundabout way of doing things, so hopefully OP can find a 3rd party add in for the IDE or favorite text editor.

Or you could leave all the errors in there. It makes the final product sparkle.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's got to be a static variable:

struct example{
static int id;
float gpa;
string name;
};
int example::id=34440;

Should be identical for the class (static variable/defined after the declaration).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, you can have functions in a struct (when speaking of the C++ variety -- C structs can only have function pointers). The only difference between structs and classes is the default access specifier.

class MyClass
{
     int a;
}; 

struct MyStruct
{
     int a;
};

In each case is "a" public, private, or protected?
For class, the default is private. For struct, the default is public.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Seems to depend on which IDE you use. Visual Studio has some 3rd party tools available (see this article).

If you just have a text editor you can probably write a program to pare down your code to the strings (marked by a line number), import that into word, correct everything and make your changes by hand.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the "default access specifier" for each?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Unfortunately, when people are taking a course instructors often put things like the STL off limits (which provides for some great opportunities to reinvent the reinvented wheel). Also, giving the OP a solution in a can doesn't do much to help their learning process.