Ass Hat
Home
News
Events
Bands
Labels
Venues
Pics
MP3s
Radio Show
Reviews
Releases
Buy$tuff
Forum
  Classifieds
  News
  Localband
  Shows
  Show Pics
  Polls
  
  OT Threads
  Other News
  Movies
  VideoGames
  Videos
  TV
  Sports
  Gear
  /r/
  Food
  
  New Thread
  New Poll
Miscellaneous
Links
E-mail
Search
End Ass Hat
login

New site? Maybe some day.
Posting Anonymously login: [Forgotten Password]
returntothepit >> discuss >> Any C++ geeks here? by eddie on May 2,2006 5:18pm
Add To All Your Pages!
toggletoggle post by eddie  at May 2,2006 5:18pm
i have a bit of code that should work that doesn't, me and my teacher have been puzzling over it for 2 classes now.

i have a while loop that contains 2 if statements and after that i have a call to a structure. The problem is the while loop completely skips over the structure and just continues to repeat the if statements.

there is no problem with the structure, because i use it in the program already and it works fine. the spelling is also correct, almost all obvious problems that could be wrong with it i've gone over at least 4-5 times.

It's really basic C++ and i need new ideas to try and fix it.

I'd post the code but it's about 19 pages worth. I'm making a text rpg for a final. I'll post the segment if anyone thinks they can help.



toggletoggle post by ShadowSD at May 2,2006 5:44pm
eddie said:
i have a bit of code that should work that doesn't, me and my teacher have been puzzling over it for 2 classes now.

i have a while loop that contains 2 if statements and after that i have a call to a structure. The problem is the while loop completely skips over the structure and just continues to repeat the if statements.


Logically, I would assume that the structure is skipped over because the call to it never occurs, which means that the if condition which leads to the call is never satisfied.

The first approach would be to look at the code and test whether the condition in that if statement is ever true, for example by changing the second half of it to print a character on the screen when the condition is true. If the character doesn't ever print when you run the program, there's your problem: the if condition is never true, so the function is never called. If it does print the character on the screen, the problem must be something else (mostly likely a simple, hard to see typo hidden somewhere)

That's my best guess without seeing the code.



toggletoggle post by the_reverend   at May 2,2006 5:47pm
you can't use gdb?



toggletoggle post by Aegathis  at May 2,2006 6:19pm
Ive been getting a few C+'s latly, but by no means does that make me a geek



toggletoggle post by the_reverend   at May 2,2006 6:24pm
I've been coding c++ since at least 1995.



toggletoggle post by DertoxiaNLI at May 2,2006 7:09pm
I would say check to make sure your have compound if statements



toggletoggle post by nick   at May 2,2006 8:36pm
programming with c++ is like building a space station out of legos and pipe cleaners.



toggletoggle post by eddie  at May 2,2006 8:45pm
gdb? is that some type of check software?

it can't be a spelling error because if that were true the program i'm using wouldn't allow it to work at all. The program runs it jsut doesn't do what i want and skips over the call structure.



toggletoggle post by eddie  at May 2,2006 8:46pm
H.ehp1=8;
while((H.hp>=1) && (H.ehp1>=1))
{
getch();
//enemy attack
srand(time(0));
y=rand()%10+1;

if(y>=4)
{

cout<<"he bites you and takes away 2 health points"<<endl<<endl;
cout<<"------------------------------------------------"<<endl<<endl;
H.hp=H.hp-2;
}
if(y<=3)
{
cout<<"the Chupacabra screems in fury, and the top of it's lungs"<<endl;
cout<<"It sucks your blood and cuts your health in half"<<endl<<endl;
cout<<"------------------------------------------------"<<endl<<endl;
H.hp=H.hp/2;
}

cout<<"your hp has dropped too:"<<H.hp<<endl<<endl;
cout<<"------------------------------------------------"<<endl<<endl;
//use func your attack

H=fight1_sequence(H);
}



toggletoggle post by eddie  at May 2,2006 8:48pm
the while loop works because you die after a number of attacks, The structure is skipped over and it pisses the living hell out of me.



toggletoggle post by ShadowSD at May 2,2006 9:01pm
From what line to what line is skipped?



toggletoggle post by the_reverend   at May 2,2006 9:03pm
gdb = linux debugger. you can't set a break point in there?
what are you using to compile this?
just set a breakpoint at:
y=rand()%10+1;

and see what y gets set to.
or, if you don't have a debugger, print out y below the line I just pasted.
also, if(y<=3) change this to else since there is no reason to hit both the first if and the second if.



toggletoggle post by ShadowSD at May 2,2006 9:05pm
Oh wait, I get it, only one line is skipped... the enemy attack, right?



toggletoggle post by ShadowSD at May 2,2006 9:07pm
I now realize I read the original problem wrong, listen to Rev...



toggletoggle post by the_reverend   at May 2,2006 9:13pm
I've been writing software since I was like 7.
that was 1982-3-ish.



toggletoggle post by eddie  at May 2,2006 9:23pm
ShadowSD said:
Oh wait, I get it, only one line is skipped... the enemy attack, right?


no, H=fight1_sequence(H); is skipped

the srand and if work fine

i'm gonna try everything rev suggested tomorrow in school, i don't have a compiler on my home computer.

rev i'm using turbo C++ and some other dos based compiler in school.
i don't have any idea what a break point is, but i'll be sure to find out.




toggletoggle post by ShadowSD at May 2,2006 9:32pm
I started programming Basic on my Atari in early 1984. I was 4 at the time.

Of course, Basic is useless, and the languages I learned later on (C, Javascript, a tiny bit of C++) I haven't used in years, so I'm actually totally incompetent at this point; without some serious refreshment, I couldn't write an interactive program for you right now in any language. I only tried to answer the question because I've always had a good mind for the logic of it, and in that sense all computer languages are the same (it always helps to read the question right, though). In conclusion, listen to Rev...




toggletoggle post by ShadowSD at May 2,2006 9:39pm
eddie said:
ShadowSD said:
Oh wait, I get it, only one line is skipped... the enemy attack, right?


no, H=fight1_sequence(H); is skipped


Oh, right, the enemy attack was just a note for the programmer, whereas as the above line is the name of the function (structure) being called with the variable being sent to the function in the paranthesis. Of course, it's all coming back to me now...



toggletoggle post by the_reverend   at May 3,2006 4:09pm
turbo c++? geez.. I used that back in college. that's wicked old. right now, I use MSDN 2003. I was using 2005, but the MFC 2.0 aren't out of beta so most people only have MFC 1.1

so.. put a break point here:
H=fight1_sequence(H);
and step inside it, see what it's doing.

if you are command line on a linux system, do a man gdb it's a gnu debugger. a "break point" is just a point at which your program is stopped by a debugger. then you can check values, evaluate and change variables. I'm knee deep in a java debugger right now cause I can't get this stupid abstract panel to be loaded when it's underlying UML model is update and it's components are reloaded. no that makes no sense~!


anyhow, ShadowSD: javascript is not a programing language, it's a scripting language. BASIC is a interpreted language, but those are basically scripting laguages. on a typical day, I use: C++, C#, java, and php(w/ jacavript, vbscript, mysql, html), but my job requires me to know perl, tcl/tk, VB, asp/x/a, C, c-script, and anything else that might annoying come up.


eddie: from your code, there are a million easier ways to do this. 19 pages of code is too long. if I were doing it, I would make a Model and then store my rules/data inside a XML file. then you just have to jump through a XML file and your program would interpret what to do. sort of like a pick-a-path with reasoning, data, and whatever else in a XML node. If you really get stuck, I could debug the code in MSDN I'm sure.



Enter a Quick Response (advanced response>>)
Username: (enter in a fake name if you want, login, or new user)SPAM Filter: re-type this (values are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, or F)
Message:  b i u  add: url  image  video(?)show icons
remember:Crafted Cannibalistic Death Squad
[default homepage] [print][5:40:46am Apr 25,2024
load time 0.01376 secs/15 queries]
[search][refresh page]