jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you pop all of the elements off of your existing queue to view them, then there will be an empty queue. I was presuming you wanted to be able to view the copy of it while leaving the original intact.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know if this was the intention, but perhaps make a copy of the queue and pop all of the elements off? (no warranty granted on this one lol)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In 42 through 47, you never subtract off the part of the number that was just added to the string, so number is still = 467, which is greater than 9 so your last if statement gets skipped over.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just rewrite the skeleton and copy and paste the old information in

if( )
{
    if()
    {

    } //close inner if

    else
    {

    } //close inner else
} //close outer if

else
{



} //close outer else

Make little notes like that to yourself to verify you're closing them at the right place (just for now). The issue with yours is that you don't close down the inner if statements at the right spot.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Initializing it like that only works when you're declaring it

char addr[] = "Cane Gardens";

but not after.

For your case, you can copy a string in directly:

strcpy(account[0].address,"Cane Gardens");

Just remember there is a null character ('\0') at the end of "Cane Gardens," so make sure your address array is big enough to hold whatever you copy to it plus the null.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have:

An array of structs, account that is type electro.
account[0] is the first of the structs
account[0].address is the character array (a C-string if it's null terminated)
account[0].address[50] would be the last [B]character[/B] of an array that's 51 members long, which is one more than your array has

You can't just redeclare address like that, it's already declared in the struct. Rather than try to copy it in character by character like that (which might work under some circumstances, I can't remember), you should just strcpy your initialization string into it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at what you are trying to do, you are trying to place a bunch of characters into a spot that is one past the end of the address array (it goes from indexes 0 to 49)

Check out strcpy to get the string into address, as someone had suggested above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And isn't that how structures are declared??

The structure itself is more likely to be declared globally (though they can just as easily be declared within main or another function). The array of structs, maybe... but it's much safer to have that in main or somewhere else and pass it around via function parameters. When you are referring to specific members of a struct like account[0].yada, they have to be placed in one function or another, they can't just exist freely.

It's not a tutorial per se, but check out the C FAQ (http://c-faq.com/). It has a lot of good information on various sub-topics. Check out http://www.eskimo.com/~scs/cclass/cclass.html (scroll down and click on the intermediate notes, those start right at structures).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, as was said, 13 and 14 need to be placed in a function somewhere. Since your array is global (which isn't the best idea, but can be changed later) then they can go anywhere.

I had told you, you don't need the "electro" designation at the front of those two lines because account[0] is already of electro type.

Look at lines 60-61 for a minute. Firstly, you can only return one value, and secondly if you return from the function (line 60), the next line (61) is going to be skipped anyway.

You need to find a text or a good tutorial with a section on functions. You do not need the return type when calling them.

//headers, etc.
int return_int(int input);  /*prototype, need the type here */

int main(void)
{
   int y=2,z;
   z = return_int(y); /*calling the function, don't need the return type or the parameter type*/

   return 0;

}

int return_int(int input)  /*function definition, need the return type here */
{
    return (input-10);
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need a break; after the code in each of your case statements, else the control of the switch "falls through" to the next choice.

Changing the value of loop like makes your code difficult to follow, at least in my opinion. Get some more information on things like functions, etc. and your task will be somewhat easier.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please post your modified code (since we don't know what changes you made in the interim) with code tags [code] //code goes here [/code]

Bear in mind that what your have specified in the class declaration (up at the top) must match the method definitions (the functions below).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I wanted to correct for my above post, the " character in single quotes doesn't need to be escaped.

You don't use u anywhere, so it's just assigned and forgotten.

Also, on 35, that's not going to give you the word count for the sentence, look up what strlen gives you for a result.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need the "electro" on declare anything on lines 9 and 10, account[0] is already of type electro. I think you'll need a different tactic for copying the string in too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are comparing character by character, so you need single quotes '\"' (since \" is considered to be one character).

Also, since you are comparing a true value with a true value, it will always be true, so the loop will run infinitely (and there's nothing in the loop body to change the value of u.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The +/- accounts for there being 2 points of incidence if the value of the discriminant is greater than 0. If the discriminant is 0, there is one point of incidence (the first part +/- 0 gives the same point). If the discriminant is negative, there are imaginary roots and so no intersection on the real plane. It's the cases outlined in the diagram at the top of the page.

So, if the discriminant is greater than zero, you need to have one calculation for [x = Ddy + (signum) * the discriminant, y = -Ddx + the discriminant as one point] and [x = Ddy -(signum) * the discriminant,y = -Ddx - the discriminant] as the second point.

Hope that makes it more clear, if not post back. Just think of it as the solution of a set of quadratic equations and maybe it will click for you.

Valaraukar commented: Clear and concise. Very helpful! +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try using Int32.TryParse instead:

string str = "42"; //your string
int numb; //the number output from the method
if(!Int32.TryParse(str,out numb))
{
  //it failed
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edit, I had the name of your class wrong...

Post the code you tried for the pieceID part in the context so I can try it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't think this particular error has to do with the file.

TimePiece [] timePiece = new TimePiece[limit]

creates an array with room for Timepiece objects, but does not instantiate the individual objects

Around line 27 (but certainly before 33) you need something to the effect of

timepiece[i] = new TimePiece();
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's one of those questions that definitely depends on the project you are working on, etc. To me, if you know one of Java, C, or C++ you shouldn't have any problem learning the others and switching between them, but again that's just my opinion. I don't know much about Python, but it too is widely used and those that use it seem to enjoy it.

kvprajapati commented: :) cool! and nice avatar too. +12
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would invest in a good book like Koenig and Moo's Accelerated C++ (among others). Books like this take the approach of teaching C++ from the ground up, starting you out with C++ (and the standard libraries) rather than techniques drawn from C. The idea of learning C first is becoming passé, I think.

http://www.cplusplus.com/ is a great site for references and tutorials.

Others will be able to give you their suggestions, so watch for more replies.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you place your cin statement at the top of the loop, you'll get it to run once entering the loop, and then it will run first and each subsequent time through the loop. To convince yourself, try putting a cout statement in the same place and see how often it gets printed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, what we have described to you will fulfill the requirements of the assignment. Which part are you still stuck on?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where did the number 100 come from in the first place? Your best bet is a do/while loop.

If the number is not zero, the while condition will be true, and the program will loop again. Putting it in the do/while form guarantees that the program will prompt for the number at least once.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

== is used to test for equality, = is an assignment operator, also else doesn't take a condition, so it would just be:

if(PlayerTurn == true)
    //etc.
else
    //etc.

In fact, you could write it:

if(PlayerTurn)
    //etc.
else
    //etc.

because it's already a boolean variable.

Also, no ; after the else statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the designer, drag a button onto your form. Double click it, which will put an event handler in your code automatically. If there isn't a textbox already, then add one and make a note of it's name by looking in the properties window on the right side.
(let's assume the textbox's name is textBox1.


To start off, in that event handler that the ide generated type something like MessageBox::Show(textBox1->Text);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If your textbox is named textBox1, the textBox1->Text member contains the text that was typed in. Place a button on your form and double click it, and type your code in the button handler to display it in a message box or whatnot.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, I made an edit, sorry.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to #include <string> but more importantly, you must pull line 80 out of the scope of the if -- since it's declared within the braces, it goes out of scope when that block ends. Move it to line 72 or before.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i'm holding my breath!

Don't do it for too long, you'll turn blue and faint.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I strongly suggest that you enlarge "dataType".

I think you're right on about that. I had thought about it, but I wasn't sure if the extraction operator put a null at the end of C-Strings. Evidently it does (which makes sense):


From: http://www.cplusplus.com/reference/iostream/istream/operator%3E%3E/

Extracts characters and stores them as a c-string (i.e. in succesive locations starting at location pointed by str and terminated by a null-character). Extraction ends when the next character is either a valid whitespace or a null character, or if the End-Of-File is reached.
The terminating null character is automatically appended after the extracted characters.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://support.microsoft.com/kb/955938 (change your button Click() event to a MouseClick() event). You still get the "flash" on the button if the user hits spacebar, but it doesn't do anything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post up the entire data file? I want to see if I can reproduce the error? I was able to read in the row you provided with no problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does one line of the data file look like?

Somewhere you're trying to read something that doesn't match the type you have specified for it.

Just as an example, I know this is probably not the situation you're experiencing:

file:
1 pw 30.0 2.0

int i;
int j;
double x,y;

Infile >> i >> j >> x >> y; //doesn't know what to do with the pw, stops reading

Also, why not use an array for d1 through d10?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to explicitly cast the return-type to int ** , like int **m = (int **)malloc(r*sizeof(int *));

I think this is only necessary in C++, in C there is an implicit conversion.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Test it and see if it works, but yes, that looks correct.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 23 should be openagain >> k; but see http://www.daniweb.com/forums/post155265-18.html about using .eof()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a boolean variable to distinguish whether the program has passed the empty line in the file. Once the line has past, reset the counter. If the statement about passing the empty line is false, write into the first array. If it's true, write into the second array. What you have works, so if you don't need the extra headache right now, I wouldn't worry about it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Seems perfectly reasonable. You could eliminate some of the duplicate code by detecting whether a line with a space has been read (or if the leading "up" has changed to a "uq") to separate the two, but that's just window dressing.

If there's any flexibility in the data file configuration, you may need to adapt your code to account for that (splitting the string on spaces and equals signs like I had originally suggested.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not upset, it's just that it's your assignment, so you need to put in some effort on it.

Are the points for each of the shapes together? (sh1 = shape1, p1 = point1)

sh1_p1
sh1_p2
sh1_p3

sh2_p1
sh2_p2
sh2_p3

or are they intermingled

sh1_p1
sh2_p1
sh1_p2
sh2_p2

If it's the former, there should be some delineation between the two sets, so scan until you hit that (if it's a blank line check for s == ""). Then start another while loop where you left off (the ifstream will keep track of where you are).

If it's the latter you could do something like

string s1;
string s2;

while(getline(pts,s1))  //advances the file one line
{
   //process s1 for first list
   
   getline(pts,s2); //advances the file another line
   
   //process s2 for the second list
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That sounds like the meat of your assignment. I will not be able to take you through the entire thing step by step. Give it a try on your own now that you have some of the basics covered. If permitted, post your code attempt and someone can take a look at it for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right, so you want your substring to start at 20.

You should compile it and check, though.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can access the x and y of the ipcounter-th point by pt[ipcounter].x and pt[ipcounter].y substitute those in on lines 35 and 38.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 28 should be eliminated.

You will probably want to declare an array of points (or a vector if you don't know how many you will have) somewhere around line 20 or wherever it makes sense.

In this example, as long as you have declared a point pt, you can use pt.x and pt.y anyplace you would ordinarily use a double.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, apologies. It's either one or the other. Presumably you'll want an array of points, so you can incorporate the code into your while loop and increment an index to keep track of where you are in the points array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to use the .c_str() method of your strings to get their C-string representation:

point pt;
pt.x = atof(xcor.c_str());
//etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are your numbers guaranteed to be a fixed number of digits? If not, you'll have to do the splitting like I was saying.

For the way you have it:

point pt;
stringstream ss(xcor); //set up a stringstream with the first string
ss >> pt.x;  //extract the number
ss.clear();  //reset the stream to the beginning
ss.str(ycor); //set the stringtream to the second string
ss >> pt.y;  //extract the second number

be sure to #include <sstream> Something like atof is also a possibility if you wanted to go that route.

Put your getline statement in the while loop to drive it rather than using .eof() (which can read the last line twice in some cases)

while(getline(pts,s))
{
}

Also, main is never void, it always returns an int according to the standard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read a line in the file into a std::string with getline() and then parse that string with a stringstream.

I'm not sure it's the most efficient way to do it, but to start, break it in half on the space, then read the halves up until ':' and throw that part away, then read in the numbers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The size of an array must be a constant known at compile time. You should dynamically allocate it char * fileTemp = new char[fileTempsize]; instead. Some compilers are able to do what you tried to do, but it's an extension and is non-standard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
int i = 0;
    int j = 0; 
	 while([B]i <= 2[/B]){
         while(j <= 8){ grid[i][j] = 0; j++;}
         j = 0;
         i++;
    }

Why are you only going up to 2?

There's nothing wrong with the way your loop is structured, except for that index (and MasterGBerry's works fine too), but I think it's much easier to read with a for loop:

for(int i = 0;i<4;i++)
{
    for (int j =0;j<9;j++)
    {
         grid[i][j] = 0;
    }
}
//braces added for clarity
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What did your nested for loop look like?