Computer Science Canada ACSL question |
Author: | AsianSensation [ Sun Jun 22, 2003 9:32 pm ] | ||
Post subject: | ACSL question | ||
I am doing some old ACSL question, actually, this one to be exact: http://www.acsl.org/acsl/96-97/pdf/jr/prog2.pdf anyways, I did the question in C++, but I dont know why it doesn't work, I did it in turing, and it worked, and I don't know what's wrong with it. could someone please help me? btw, the question required input from file, but since i don't know how to do that, i made it keyboard input.
|
Author: | SilverSprite [ Mon Jun 23, 2003 9:01 am ] |
Post subject: | |
Ok i dont know the question becomes i'm too lazy to read it but the problem might be all the pos[wahtever][whatever]++1 and the count++1; You shouldnt have the ones there. Also watch your array subscripts dont go out of range.. c++ doesnt warn you about those.. |
Author: | AsianSensation [ Mon Jun 23, 2003 3:47 pm ] |
Post subject: | |
so instead of using count++, I should use +=1? |
Author: | Catalyst [ Mon Jun 23, 2003 3:48 pm ] | ||||
Post subject: | |||||
in ur prog u have
you only need
hould be |
Author: | SilverSprite [ Mon Jun 23, 2003 4:21 pm ] |
Post subject: | |
Ok what part of "the 1 shouldnt be there" dont you get asian:P *sigh* hopeless |
Author: | AsianSensation [ Mon Jun 23, 2003 4:45 pm ] | ||
Post subject: | |||
.....man, Im so stupid.....*smaking self over head anyways, I dont think that was the problem, I think the if statement are the problem
When I tried to use that, it outputted "Boo!" every single time, even if I entered "a". |
Author: | SilverSprite [ Mon Jun 23, 2003 7:34 pm ] |
Post subject: | |
Nope the if statements arent the problem.. Do you know the difference between a char and a string.. doesnt look like it... |
Author: | Homer_simpson [ Mon Jun 23, 2003 8:35 pm ] |
Post subject: | |
y not use string instead of characters? |
Author: | AsianSensation [ Mon Jun 23, 2003 8:54 pm ] | ||
Post subject: | |||
uh......string? nope, still haven't learned string yet.... but I asked bugz, and he said i could use
that worked, but still, the program isnt working, i'll go and try and fix it, and maybe learn string while im at it. |
Author: | Homer_simpson [ Mon Jun 23, 2003 9:25 pm ] |
Post subject: | |
well yeah you could check it like this i guess if ((type[1]=='a')&&(type[2]=='\0')) then yay!! but strings are much much easier... |
Author: | rizzix [ Tue Jun 24, 2003 1:48 pm ] | ||||
Post subject: | |||||
u see c++ is backward compatible with c so that works. yes, use pointers to char instead. so all u have to do for checking:
|
Author: | SilverSprite [ Tue Jun 24, 2003 7:43 pm ] |
Post subject: | |
That's what i meant by strings and chars Asian.. double quotes for strings and single quotes for chars.. a char is only one character hence char(acter) and a string is for multiple characters hence a 'string' of characters..tut tut turing corruption.. |
Author: | AsianSensation [ Wed Jul 02, 2003 9:55 pm ] |
Post subject: | |
ok, then can someone give me a tutorial, or a site on how to use strings? |
Author: | UBC_Wiskatos [ Wed Jul 02, 2003 10:26 pm ] | ||||
Post subject: | Re: ACSL question | ||||
AsianSensation wrote: I am doing some old ACSL question, actually, this one to be exact:
http://www.acsl.org/acsl/96-97/pdf/jr/prog2.pdf anyways, I did the question in C++, but I dont know why it doesn't work, I did it in turing, and it worked, and I don't know what's wrong with it. could someone please help me? btw, the question required input from file, but since i don't know how to do that, i made it keyboard input.
Hmm... I don't know what you're doing with "pos [posx-2][posy-1]++;"... or the similar array types, are you trying to increase their value? You have to be careful because an array in C++ is actually a pointer, and using ++ might actually increase the memory location, not the value of the actual address (I say might because I've never done a ++ on an array before). So what you want to do is try replacing those with "pos[posx-2][posy-1] += 1;" Also, your last for loop initializes a low bound of integer k yet binds it by a high bound of the integer i, and increase integer i, while k remains at 0. Also, your shape definitions seemed wrong to me... Here's the rewritten code:
|
Author: | rizzix [ Thu Jul 03, 2003 9:50 am ] | ||
Post subject: | |||
about using ++ it's allright. dosen't affect the pointer onlyt the contents, as long as he defined the array as a 2 dimensional one and he has 2 [][] thats all. and here's the working code without much changes:
EDIT: actually i changed it a bit to make it more compatible with newer compilers |
Author: | AsianSensation [ Thu Jul 03, 2003 9:24 pm ] |
Post subject: | |
ok, I changed the code around(see edit), but still, it won't output anything, the cursor just flashes. UBC_Wiskatos's works, except I don't know that much about what he did, apparently, I skipped the case section of the tutorial. so what's wrong with it now? |
Author: | UBC_Wiskatos [ Thu Jul 03, 2003 10:10 pm ] | ||
Post subject: | |||
Try this: I don't think your original array values correspond to the shapes, I changed them in my code, but they're in their original form here. Anyway, the problem seems to be with the if seeing if the char is equal to a, b, or c. I think this should work. I think the core problem is that you use double quotes instead of single quotes, since single quotes are for (single-character) chars.
|
Author: | SilverSprite [ Thu Jul 03, 2003 10:58 pm ] |
Post subject: | |
you did that AGAIN!! i told you not to!! and so did so many other ppl asian |
Author: | rizzix [ Fri Jul 04, 2003 10:35 am ] |
Post subject: | |
lol |
Author: | AsianSensation [ Fri Jul 04, 2003 7:59 pm ] | ||||
Post subject: | |||||
man.......Im so messed up it's not even funny..... I found out the problem
instead, I had this:
man....Im soooo out of it..... maybe the SAT stuff is detrimental to my health... |
Author: | UBC_Wiskatos [ Fri Jul 04, 2003 9:08 pm ] |
Post subject: | |
LOL, jeez man, I told you about that error a few posts back! Those SATs are going to kill you. |