jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah give it a try. This will let you pause the screen. That way everything won't go flying by. Run your exe at a prompt to get a more accurate picture as I'm not sure (and I'm sure not gonna find out) what goes on when you run it in the shell of TC.

P.S. Also learn to use code tags. Very simple

[code]

/*code goes here*/ /*more code*/

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hey Narue!

Why can't I have groupies? I'm sure she'll be thrilled with the shout-out.

Anyway... look at line 36 in relation to your while loop. Walk yourself through a cycle or two of the loop, noting when the file gets closed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use the function getchar() to pause for the user to hit a key. You can use an if statement with the modulus (%) operator to set how many lines you want before the user is prompted.

For example 0 % 50 = 0, 50 % 50 = 0, 100 % 50 = 0.
See if you can come up with it.

P.S. To see where your prior output has gone you can scroll back in the cmd window. If you are using windows you can set the scrollback buffer by going to the system menu (upper left hand corner) of the cmd window, Properties, Layout tab, Screen Buffer Size and adjust the height.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
else return (n / (2 * n + 1)) + seriesFunc(n-1);

The first portion is being computed with integers, so you need to cast either the numerator or the denominator (or both) to a double.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe it's a shortcut way of saying str[i] !='\0' since once the pointer hits the end of the string it will be null and therefore that statement *(str+i) will be false.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It came up as part of the default included references for me... (it's marked as a part of system.dll).

Right click on your project in the Solution Explorer, go to References, from there Add New Reference, on the .NET tab scroll down to System.Net. See if that gets it for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

pass pointers to functions instead of arrays.

Passing int list[] is the same thing as passing int *list. The array "degrades" to a pointer when it's passed in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See this post from over in C# land: http://www.daniweb.com/forums/post1129114.html#post1129114 . You'll have to translate the syntax of it to C++/CLI (M$ mungware per Salem :) ) but it'll be the same .NET functions from the System.Net namespace (HttpWebRequest/
HttpWebResponse). It was a similar problem to what you are working on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your compiler is too outdated for your OS. It's 20 years old. Get mingw with the Code::Blocks IDE or Visual C++ Express Edition.(2010 version is coming out soon).

EDIT: AD beat me.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you don't use braces to delineate your if/else groupings only the statement immediately after the if or else gets executed:

if(condition)
   This would get executed when condition was true
A statement here would cause an error when an else is present
else
   This would get executed if condition is false
   {
       The stuff in these braces would be executed if the condition was false because it is with 
        the "This would get executed" statement 3 lines before
   }
This statement would be totally on its own, not part of the if or the else

So now you see why your output on line 13 was executing regardless.

I don't have a good text recommendation for you. I used to like Kelley/Pohl "A Book on C" but it's getting a little outdated and might be a bit too dense for folks just starting out. Their book "C By Dissection" (meant for beginners) is not very effective IMO.

I'll chide you one more time about the formatting too. Read the article WaltP linked in Post #3 (it's written by some guy WaltP at another site, probably just a coincidence). It's definitely hard to match your braces up and what goes with what when everything is crammed up against the left hand side like that. If it's easier to read it's easier to help you.

Xufyan commented: great - xufyan +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

firstPerson's definition is more like one that might be used in a formal mathematical setting. Check out the second paragraph of http://en.wikipedia.org/wiki/Functional_programming for a comparison of the two definitions. I'm sure we could argue about the semantics of what constitutes a function (like "is a void function really a function by one definition or the other?") but I think WaltP offered the best approach as it seems the OP was just looking for basic info...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

int nums[14],checknum[14],displaynum[14] is how you've declared your arrays, with 14 total elements. Your loop goes 0,1,2,...,14 which is 15 elements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

to get math.h properly

I meant the math library not math.h itself. That may not be an issue any longer anyway, I'm not up on *nix at all anymore I just remember having to do that from a while ago.

Well, anyway glad it worked out for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you compiling on *nix? If so you may need the -lm switch to get math.h properly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

<deleted> Nevermind. Sorry.

See VVVVVVVVVVVVVVVV

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why not read the line in as a std::string using getline() (which will stop at the newline) and do the processing of the characters afterwards?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since I cannot edit the post, I'll just add another reply here.

I think the reason for the way huge number is because your array is un-initialized. In case anyone (who didn't know already) wants to know. :)

I wasn't undermining what you wrote at all. Sorry if I wasn't clear about that. I was just warning against another issue that was going to manifest itself one way or the other.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

while (cin >>Yes); is not doing what you think it is doing. You've already asked for input into Yes within the loop on line 32. This will prompt you for input again but regardless of what you put any input will cause the loop to continue because cin returns the equivalent of true (in reality an object of type istream whenever something is successfully converted vs. a null value if nothing remains) thereby driving your loop for one more cycle. You also haven't changed the type of Yes to a string. Once you've done that, having your while condition be while(Yes =="yes"); will do the trick. To make sure you catch all the variants,Yes, YeS, etc, consider converting (the variable) Yes to all lower case.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are trying some creative coding there. You need to make Yes a string and then compare it to "yes." For example,

cout <<"Enter another pt? ";
cin >>Yes;
if(Yes == "yes" || Yes == "Yes") //and any other variants you want 
{
   //do something
}

The fact that your variable is called Yes has nothing to do with what it contains.

Note that you might want a do/while loop around your prompts so you can ask for points over and over (and you wouldn't have to repeat all the code for your questions).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well vmanes, that was a well-deserved semi truck driven through that garage sized hole in my knowledge :)

I do normally test these things. I went and tested to see what I was really thinking of and I guess that I made too much of a generalization from the stream problems resulting from combining cin and cin.getline. I had also misunderstood that the OP had been feeding 2 chars into the cin. Apologies to the OP.

Also thanks for the heads up on the Debug vs. Release behavior.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Carl Volt, Frank Amp, James Watt, Bob Transformer

...was priceless LOL

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What's actually happening is something a bit different

cin >> ch1;
cin >> int1;

ch1 is a char so it holds 1 character. When you are typing in the character to go into this variable, you hit enter. Enter is a character which remains in the input stream and is processed by the cin >>int1; call which interprets it as "someone has pressed enter" so it skips the statement entirely without letting you enter an integer. The answer above about int1 being an uninitialized value is pretty much correct (though I believe it's more that the compiler sets aside an "empty" portion of the memory which could have any state and not so much that it assigns the memory an arbitrary value -- I may be inaccurate on that point).

P.S. You can eliminate that extra newline from the stream by placing a cin.ignore() between the 2 lines above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Beware of this in your function:

double average(int sum, int numElms)
{
	//int i;
	double avg;
        avg = sum/numElms;
	return avg;
}

Since the two operands are integers the result placed into avg will be an integer result (so truncated or 0 if the denominator is bigger) despite the fact that it's a double variable. Cast one (or both) of the operands to a double to get the correct answer. avg = ((double) sum)/numElms;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

else if (randomNumber >= 31 && <= 59) is not valid syntax it must be else if (randomNumber >= 31 && randomNumber<= 59) . The same thing for line 34.

As an aside, you only need to call srand one time in your program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

He didn't specify, but from another post I believe he is doing a CLR winforms and not an MFC application.

It would be:

comboBox1->SelectedItem  //The selected item (of type "object")
                                          //must be casted before using
comboBox1->SelectedIndex //The (0 based) index of the item
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I used something like this to get the index of the split:

Random rand = new Random();
int [] a = {1,4,5,3,1,4,6,7,8,1};

int [] spl = new int[4];
spl[0] = rand.Next(1, a.Length - 2);
spl[1] = rand.Next(1, a.Length - spl[0] - 1);
spl[2] = rand.Next(1, a.Length - spl[0] - spl[1]);
spl[3] = a.Length - spl[0] - spl[1] - spl[2];

accounting for the fact that each split had to hold at least one number. I hope that's the setup you had in mind with the 4 partitions randomly along the array.

After that it should be easy to get the subarrays (perhaps having lists might make things even easier)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use something other than x because that's already changing in your loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

scanf("%d",&a); is reading the numbers into the same spot in the array "a" over and over again. Hence all the other spots are stuck with their uninitialized "values." You can fix it by using the index x as scanf("%d",&a[x]); but see http://www.daniweb.com/tutorials/tutorial45806.html for some safer alternatives to scanf.

There's one way to measure if your sort works. Test it out (it does seem to work -- but your looping over your function multiple times in main is extraneous).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't believe that you can call VectA.reserve() out in the middle of nowhere like that. I'm assuming this is a paraphrase of your code. Moving the reserve call to main() (after creating a main) I was able to get it to compile and give a size of 0.

Edit: Also make sure if you are compiling on the command line that you present them in the order globals.cpp and then main.cpp on the list of files.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I overgeneralized for brevity's sake. The questions came from an article on the scientificblogging site

My bad, I wasn't sure if you were posing them rhetorically or not. I hadn't realized it was such an active area of research at present. That article was a good read, the one about microtubules. Interesting stuff...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a is a char and " " is considered a string. When comparing something with a char, use the ' ' (single quotes).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The whole idea of the overloaded operator is you can now say something like if(Rational1 < Rational2) and it makes sense to the compiler because it has an overloaded operator to tell it how to perform the operation.

However, you have to implement it in your source file like you did on lines 90 to 98 above. Tetron's method of having one parameter member functions would work too but you seem to be more comfortable this way. You can then borrow the formula that you have posted on your latest post in red and so in that case

bool operator <(Rational &Fraction1, Rational &Fraction2)
{
	return ((Fraction1.numerator1 * Fraction2.denominator2) < (Fraction1.denominator2 * Fraction2.numerator2));
}

since we want a true or false value and the ordinary use of the < gives us true if the numerator-denominator products have this relationship. Therefore, reducing the problem to comparing integers (which is something the compiler knows how to do) helps us to compare the objects. Also, hint, the > operator can make use of this method.

On a peripheral note, your tests function above is meaningless as you have set it up. Mathematically a rational number is any that can be expressed as the ratio of 2 integers, with the denominator not equal to 0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Edit: Nevermind, Apegram's got it. ^^^^^^^^^^^^

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a fairly lucid explanation for static vs dynamic.. This has good examples.

Another article that covers all 4 in an understandable way.

How come you gave a link for google? LOL I'd been searching all over for it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

while (newIsTherePtr->item!=item) needs another condition to ensure you don't run right off the end of the list (e.g., && it with newIsTherePtr->next !=NULL or however you designate the end of your list)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's not going to reach 5 either. The best way to do it would be to flesh out the for loop with the proper conditions (so say i=0;i<10;i++ ) and make the number of times it goes it independent of x. Either that or turn it into a while loop which breaks on some condition.

tux4life commented: Yes, that would indeed be a better idea :) +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It might have been reading the last e in "true" multiple times. I'm not sure, though.
Even working with the char * I wouldn't have read it in character by character I would have used getline and have the in.getline() statement drive the loop.
I would just stick with the std::string and then you don't have to worry about any of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also this:

int array_size = 10;
float floatArray[array_size]; // this is how we make an array

..is not allowed in C++. array_size has to be declared constant. (or use new and delete)
So:

const int array_size = 10;
float floatArray[array_size]; // this is how we make an array

LOL. My brain read const into the expression int array_size = 10. Sorry OP! Thanks "NE"

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

...my 0.02 and a borrowed dime.

>can an electromagnetic field affect a neuron?
Yes. Google "transcranial magnetic stimulation"

>does an activated neuron generate an electromagnetic field
Yes.

>if so, is that field strong enough to affect neighboring neurons
Yes, but the affect is largely unknown and a subject of current research:
J Neurosci. 2010 Feb 3;30(5):1925-36.
The effect of spatially inhomogeneous extracellular electric fields on neurons.
Anastassiou CA, Montgomery SM, Barahona M, Buzsáki G, Koch C.

>does the field have enough energy to carry information
IMO, probably. It's also probably not reliable enough to be used by the nervous system. To stretch an analogy if you have a few spotty tv stations over broadcast or 150 channels over digital cable you'd probably choose the latter.

a computer can determine what picture the person is viewing 8 out of 10 times.
These types of studies (I haven't read the one in question) can overgeneralize to the point where you can say with 99% certainty that if two of your neighbors have their porch lights on it's a Thursday.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for(int i = 0; i < array_size-1; i++) You lose the last element this way. Should be i<array_size, so if you have an array of size 3 you get 0,1,2

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the problem that you are having with it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if ( x > 3 ) x = 0; When will x ever actually reach 10?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why not make life easier on yourself you're shifting between strings and char * unnecessarily. Change temp to a std::string and change line 9 to while (in >>temp) (letting that drive the loop) and you can eliminate lines 11-21 and 23-24.

Also on line 28 you don't need the -1, you'll miss your last element that way because you are using < instead of <=

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

.i get the error that field.h does not exist..

It's reflected properly in the code that you've put up but if that's your exact error message than you've used the wrong case (f versus F) in one of your cpp files.

One of the main problems you'll face after that is you forgot to declare your private member variables in the header (e.g., size and data).

Take a look at the following declaration and see if you can spot the two things wrong with it: double & operator[]; (constant unsigned int); Also, if you have

using std::cout;
using std::endl;
using namespace std;

the third line makes the first 2 redundant.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See, I think you are running into problems because you're supposed to have one rational number per object. Then if you are comparing two rational numbers it will actually mean something.

You have sort of the right idea but you want to compare the numerator and denominator of the object in question to another one (e.g., 1/2 or 1/5 which is bigger, by your definition neither is). Otherwise you can make a two parameter version be a friend function to your class but I'm not sure if that's in line with your objectives.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

To write the operations to a file, open up a filestream object, fout, and I would simply direct your operations into it as you go.
When the user hits plus, fout <<" + "; Unless you wanted to wait until the end of the line to make sure the user doesn't press clear or something. In that case you could keep concatenating the operations onto a string: calculation+=" +" ; at the end of the line, fout <<calculation<<endl;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For the purposes of your program it would only be one type. The user would never see the 1 thru 13 holding the value. Output can be placed in a "helper" function where you pass in card and house and you get a string back as above.
Otherwise check out something like this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You could do it with an enumeration type but the easiest way to go about it would be to store it as an integer (as you have) and only convert it to jack, queen, king, ace when it's displayed.

if(card == 11)
    std::cout<<"Jack of "<<house<<std::endl;
else if (card == 12)
//queen of
else if (card == 13)
else if (card == 1)
else
   std::cout<<card<<" of "<<house<<std::endl;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can I only use the curses library in a Unix environment? Or can I set it up so I can use this as is?

If you are using it in Windows, you need something like pdcurses.
They have the dlls available zipped but you can also build it into static libraries from source (extract the source code zipfile, e.g, pdcurs34.zip, and in the win32 subdirectory there are makefiles for most of the popular compilers). Make sure to edit the makefile to reflect the location into which you extracted the source.

That should hopefully give you a head start.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not alone Peter. At last count I think we had:
Nick Evan
Myself
sknake
Agni
BestJewSinceJC
experiencing some variant of what you've described over the last 3-4 months. It is known to Dani. Crunchie may be right as the deleted posts factor has been Dani's opinion as well. I had put forth the idea that one indicator was counting reported posts as an entry in the bad post forum but that doesn't explain the solved threads bit.