jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Will your instructor vary up the input file any? Since you are hard-coding the array dimensions anyway you could potentially (though with loss of flexibility) get your input via 3 nested for loops stepping through the array.
This

if(c>3)
{
      c=0;
      r++;
      cout << endl;
}

if(r>12)
{
      r=0;
      l++;
 }
  c++;

may or may not work but it's kinda kludgy either way.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes and change it down where you display the entry after entering it in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have selected a Windows GUI application project within the IDE. I haven't used C::B in a while so I don't remember their terminology but you want to select a "console application" instead. Start a new console project and import your code back into it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I haven't been able to find it either. I know on the test run that I just did I added a reservation at 2 4 4 and it showed up in array postion 1 3 3 like I expected but it also showed up in 0 7 3 (another run had 2 5 2 show up as 1 4 1 and 0 8 1. I'm sure you'll kick yourself when you find it...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, I think I hadn't uncommented the spot where you add 1 back to all the values. Shouldn't have made a big deal. This time it adds two reservations to the ship the first time but I still don't get any junk output.

You have booked the Cabin on Level: 1 Row: 7 Colunm: 2
****
****
****
****
****
****
*X**
****
****
****
****
****
****

****
****
*X**
****
****
****
****
****
****
****
****
****
****

****
****
****
****
****
****
****
****
****
****
****
****
****

Would you like to try another cabin? Y/N
y
Which Level Would you like to reserve? 1-3
3
Which Row Would you like to reserve? 1-13
12
Which Columm Would you like to reserve? 1-4
4
You have booked the Cabin on Level: 3 Row: 12 Colunm: 4
****
****
****
****
****
****
*X**
****
****
****
****
****
****

****
****
*X**
****
****
****
****
****
****
****
****
****
****

****
****
****
****
****
****
****
****
****
****
****
***X
****

Would you like to try another cabin? Y/N
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a sample from one run. It doesn't seem to have booked the last entry but the first two worked:

You have booked the Cabin on Level: 1 Row: 3 Colunm: 2
****
****
****
****










****
****
***X
****










****
****
****
****










Would you like to try another cabin? Y/N

You have booked the Cabin on Level: 1 Row: 2 Colunm: 1
****
****
****
****










****
**X*
***X
****










****
****
****
****










Would you like to try another cabin? Y/N
y
Which Level Would you like to reserve? 1-3
3
Which Row Would you like to reserve? 1-13
13
Which Colunm Would you like to reserve? 1-4
4
You have booked the Cabin on Level: 2 Row: 12 Colunm: 3
****
****
****
****










****
**X*
***X
****










****
****
****
****










Would you like to try another cabin? Y/N
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i changed my while loop to look like this:

while (indata != NULL)

If it still works fine but my intention was something different. I'll show you what I mean when we get this other bit straightened out.

Also i changed my array to initialize it, using a blank space, an 'X' and a 'B'. and it seems that is what is the first character that comes up when i output the data later in the program.
Also i am still getting alot of spaces and then a few lines and spaces of the symbols still

Can you put up the code that you used to initialize it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use strcpy to copy those values into the character array:

#include <cstring> //to access strcpy
switch(col)
{
   case 1:  strcpy(text,"0x00000000");
   break;
      //etc.
}

You can only assign text to a character array in the manner that you are trying when it is first declared.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Jonsca:
by "infile.eof()" do you mean "indata.eof()"? and if i take it out that will mean that it will not know when to stop reading the file.

Yes I meant indata. I'm talking about a situation where you use your indata>>ch as the loop variable for the while loop so that when you run out of characters it returns null and the loop ends. The .eof method is prone to scanning in the last character multiple times. Read this post by Dave Sinkula it gives all the details. For right now, though I don't think it's the primary problem but I was examining it as a possibility before.

WaltP:
when it reads a character i get it to display the character so that i can see that it is reading it right. am i doing it wrong?

Unless you're doing something fluky both times and everything's coming out right side up by chance I think that part is ok. Don't quote me on that.

what i want to do with the data later on is change one char, in a certatin spot in the file to an 'X' to represent a reserved spot in my database.

jonsca:
i changed line 9 to what u said but now i am getting a bunch of blank spaces and an 'X'. and then more spaces then another 'X', then spaces and random symbols again.

And it seems to be doing that okay on my end it's just there's …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change line 9 to: char cabin[3][4][13]= {' '}; ** I should have thought of this earlier but the array was not initialized so you were printing out junk characters that were there when the array was created.
It may not solve all the problems but this explains what you were seeing.

I think the input is probably ok as it echos properly on the screen.

** This seems to work but I do not know if that's the proper way to do it. It won't allow any other characters in it's place.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is all happening from the output that's generated in lines 61-70? Ok, I was able to reproduce it. If that's not where it is we can look at some other areas.

I don't think it's related but you can eliminate the use of infile.eof() as your loop condition -- as using that can go one past the end of the list because of the way that method is designed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you put up your current code. Also, specify where you are getting the random symbols.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, except that's going to fill in a different order than 0,0,0 -> 0,0,1-> 0,0,2->... since the middle index will progress first. If you're going to have to read the file ( you wrote out) back into the program at a later time you'll want to keep a consistent format. That way your reading and writing loops will be similar to each other.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I changed the header file name?

Yeah, sorry about that one it was an assumption on my part that was false.

How are you compiling these two files? Did you try what I suggested in the other post, to compile the file from lines 1-54 before the main file?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

well i have changed them to cabin[3][4][13] now. should i change the for loop and get rid of the minus 1 to lvl, row, col and plus 1 parts lvl, row, col?

No, don't change the -1 for any of the dimensions, as you still need that since you are going from [0][0][0] to [2][3][12] over the range of the indexes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Except you missed the critical part: textBox->Text = textfile; and the streamreader is not called mystream, so just do sr->Closed();

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Apologies. I don't know why I was under that impression. Tried it out and as usual Mr. P is right.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Actually that may be a big part of your problem. Are you overrunning the array when you try to write it out? I'm not convinced you're reading it in as you want to either...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A quick point before anything else

there are 3 levels in the cruise ship, with 4 colunms and 13 rows. that is where the 3d array comes in "cabin[2][3][12]".

is incorrect. If you had a cruiseship of those dimensions the indexes of your array would go from cabin[0][0][0] to cabin[2][3][12] but your array must be declared

char cabin[3][4][13];
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, that was exactly what I needed. One more thing, how would I change the input method in a way that would allow me to use an unlimited amount of characters without underscores? I realized that you would need to change the declaration of the intial variable from the char charName[50] to string charName and probably the cin.getline(charName, 50) to getline(cin, charName). but would you need anything else to make sure there aren't any errors?

The way you described should work just fine. You'll still need the cin.ignore before the getline(cin,charName) statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How are you getting the input for the variable "input"? If it's a cin >> as I suspect it is, now you would need the cin.ignore() after that cin statement or before the cin.getline on line 29. You can use that variant of ignore() you had before but since it's probably 1 newline gunking up the works the cin.ignore() with no arguments will probably suffice.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you show an example data file? I think if you know all the dimensions ahead of time you could just use a for loop to read in the data and make things slightly easier on yourself.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 99: There's an issue with case sensitivity here. In one file you include the header as "Point.h" and in main you include it as "point.h". If that's not the case make sure that your class cpp is getting compiled before your main cpp.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's initializing a character array of length 1 with the null character.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Replacing line 29 with cin.getline(charName,50); would be the best way to go.
The cin.ignore helps in the situation where there are newlines ('\n', resulting from pressing enter after your input) left in the input stream.
Since you would have the cin.getline statement first and then the cin >> there won't be a problem with an excess newline being left in the input stream since cin.getline reads in and disposes of the new line character (versus having the cin >>statement first which can leave an extra '\n' in the stream to get picked up by a subsequent getline thereby ending the getline before it starts).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
int x,y;
for (x = 0;x<=384;x+=3)
{
    for (y = 0;y<155;y+=3)
    {

will get you

{0,0},{0,3},{0,6} .....
{3,0},{3,3},{3,6} .....

So it will be compressed in both directions. You may need to adapt it to map properly onto your output device (so send {0,0} to pixel {0,0} and {3,0} to pixel {1,0}, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, the reason you get the error is that what you have is not the proper syntax for a "for" loop. I was just suggesting declaring them in the body of the for loop but you are correct they won't persist if you do that.

I perhaps misunderstood what you needed, for that I apologize. However, I'm confused as to why you read in all of the y values with a constant x and only vary x once you've reached 155 on the y. Rather than the x++ and y++ in post #2 you could probably use x+=3 and y+=3 to skip the proper lines.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A better way (though not the only way) to write it would be with a nested for loop:

for (int x = 0;x<=384;x++)
{
    for (int y = 0;y<155;y++)
    {
//this way you wouldn't need the int x=0 and int y=0 at the top

because even if you were to use the two conditions in one loop you'd have to && them or || them together.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, so you know that's not correct but how can you change it? In this case ptrnSize is not the right number of stars. Go back to post 28 and read it again. How many do you need on each row? It varies, but what does it vary based on?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try putting a for loop in that spot and seeing if what if anything you could accomplish with it? It's a for loop to print the stars on the left side of the picture.
It needs to print (for a seven line shape):

(zero stars) line 1 -- based on you going 1-7 rather than 0-6
*
**
***
**
*
(zero stars again) line 7

After you've printed those on the appropriate lines, print out the rest of the line. There's a change you have to make so that you don't get extra characters that go beyond the end of the line. Just see if you can do this first part before that. You should be experimenting with it until you get it right or sitting down with a piece of paper and plotting it out. No one is going to do this for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: Add another for loop at lines 8 and in between lines 19 and 20. Use it to print the first stars of the row. Modify the starting point of your for loops on 9 and 21 to take this shift into account.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you add the additional stars to the left margin? There's 0 on the first line, 1 on the second line, ..., up to (rows/2) stars in the rows/2 line and then down from there,...,1 on the second to last line and 0 on the last line.
i and k are your row counters in the code above -- use them to know how many stars to print at front of the line. It's going to push your rows out beyond the end but you can take care of that in the next step.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

output linenumber-1 * and then an &.

He's given you a good clue there. See if you can get the stars in front of the & at the left border of your creation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I shouldn't reply since you keep bumping this... So what do you believe you have left to do? Looks to me like it's putting stars to head up the front of each of the rows and that you have to push some off the end those rows that receive extra stars. There's probably a bunch of ways you can pull it off.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

textfile and fileName are just string^s declared elsewhere. I was just using the caps as labels, wasn't yelling lol.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a StreamReader object (in System::IO) to read in the text from the given filename as a string. You may be able to send it right to the textbox from there.

Here's the code I used:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
      OPEN DIALOG
      StreamReader^ sr = gcnew StreamReader(fileName);
      textfile = sr->ReadToEnd();
      CLOSE STREAMREADER
      SEND TO TEXTBOX
			
}
private: System::Void openFileDialog1_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) 
{
     fileName = openFileDialog1->FileName;
 }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That was your code that I had pasted in. I was just trying to narrow down the window for you to find the spot for it. You've got j in the right spot now. Use it to index your newstr array, so newstr[j] instead of i. Trace a sample run through by hand (or with your debugger) and see what the results are.

restrictment commented: Thanks a bunch! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
int j;//my addition
while (str[i])
  {
    if (ispunct(str[i])==0) 
	{
	newstr[i]=str[i];
	}
    i++; //this is keeping track of str
  }

When in here do we know, ok we've got a non-punctuation character and can increment the j counter? Where can we be sure of that? So j is the counter for newstr which we would increment when we were sure of having a non-punctuation character to copy in.
Again, say we have 0 thru 6, we want to copy this into another array and we keep track of that number of items copied over:
[i|j|k] so we have 0 thru 2, and we skip the period so then we have [i|j|k|m|n|o] and we knew to put m in at position 3 solely because we kept track of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If newstr and str share the same i index, lets say position 3 of str was a period. What happens with index 3 of newstr? It'll be a gap you'll be (almost) back to your original problem.

<snip>


You need a separate index for the newstr array.

Declare an integer j (or call it counter2 or any number of things). You need to increment j every time you get a "good"(non-punctuation) character so that you know what the next slot in newstr is. Once you've hit some spaces j wouldn't be equal to i but in your code you assume they'll match up. If I'm photocopying a bunch of sheets and passing them to you to file but I'm skipping the blank sheets, how will you know in which slot to place them. I pass you sheets 0-3, skip over 4, and now I pass you sheet 5. What slot is it going into? not 5, but 4 on your side. You would keep your own count separate.

You're so close I wouldn't give up at this point.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One other thing, might be an issue:

The exponent on a variable in a term is called the degree of that variable in that term, the degree of the term is the sum of the degrees of the variables in that term, and the degree of a polynomial is the largest degree of any one term.

According to the definition you might need to take in another term so a polynomial of degree 2 will actually have 3 members (of course two of them could be 0). I believe I'm reading/remembering that correctly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If newstr and str share the same i index, lets say position 3 of str was a period. What happens with index 3 of newstr? It'll be a gap you'll be (almost) back to your original problem.

From Mr. P (my emphasis added):

2) increment indNew for every non-punctuation character.
3) increment indOrig for every character.

You need a separate index for the newstr array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So now create a new char array and copy all the non-spaces over (you could do the copying in combination with the first step if you copy all the non-punctuation over at that point). You know the new array will be less than or equal to the old one in size.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The extra '\n' from where you take in the number and press enter gets stuck in the input stream and carries down to your other prompt causing the wrong instruction error to come up (since '\n' !='y').

Here's a couple of tutorials to get you through the problem.
Particularly read the section on fgets/sscanf for your "rows" input.
http://www.daniweb.com/tutorials/tutorial45806.html
In this one read the getchar part and try to adopt it to your code.
http://www.gidnetwork.com/b-60.html

In a situation like you have here it can't hurt to initialize ch to 'y' when you declare it. As it was before the program was skipping over the loop completely.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Type "path" (no quotes) at the prompt that you are using. Make sure that your bcc directory is actually there. Otherwise you may have to write a batch file that sets these environment variables and run it each time you open up a prompt (you can automate this by creating a shortcut to something like %COMSPEC% /k "C:\Qt\4.4.3\bin\qtvars.bat" (this is an example from a prompt that Qt sets up for compilation).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does this link help? (add your Borland directory to the path)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out the functions in ctype.h (include it as <cctype>). It has an ispunct() function which you could use as you're moving through your array. See this for a reference to all the functions in that header.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Remove all the stuff related to gs_A,B,C,D. You don't need them. You are passing in the thresholds for the grades, so use them.
If I were to say, ok, answer in terms of s1, what is the highest grade acceptable for a B? What is the lowest grade (in terms of s1) for an A. Do the same for s2,s3,s4 with the other ranges. Keep your function the way it was and translate your hard coded values into ones in terms of s1 through s4.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scroll down towards the bottom of the page until you hit the Tags section (in green) move one line up from that (next to the gold "Reply to this thread" button). It says Mark as Solved.

xavier there's no reason to jump on a thread you hadn't posted on before just to say that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dereference s before you try to get the c_str() method: c = (*s).c_str(); since s is a pointer to string not a string. Or c=s->c_str(); will work too I just thought the other form was more illustrative for your benefit.

Also, strlen won't give you the length of the std::string, use s->length() (same need to dereference) instead-- unless you meant to take strlen of c instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need something like this in your moveup (for example)

if(board[i] == 0 && i !=0 && etc etc)
 {  /*for which other positions is this invalid */
     swap(&board[i], &board[i-4]);
     break;
 }
  else
      printf("Invalid move\n");