For some reason my for loop is not repeating. I have been looking at this function for a couple hours now. I cant see where the error is. This if a function for my first program, and I am sure it is something very simple that I am over looking.
Firedraco, Dont I need to declare a prototype inside the function order to use it? I am still not very clear on how it works.
Believe me, at this point I am about as confused by the behavior of the C++ language as I can get. For example: I call the rand(time(0)) in my program. Yet I have not included ctime or cstdlib librarys.
All my variable are global at this point. I found it was easiest to open notepad, and make all my declarations there. I know that is not a good habit to start. But for right now, as I am just starting to learning how to think about the program as a whole; while simultaneously thinking about all the little pieces. It helps, when I decide to add a value, to be able to just move over, declare it, use it. Instead of thinking about every function that will use it, where do I need to first declare it.
For now, all my of my variables are int, except "reply" which is a string.
If you are include stdafx.h or something similar, it is probably including ctime/the related libraries. Anyway, about function prototypes, you don't HAVE to, here are two examples:
1 2 3 4 5 6 7 8
int return_int() {
return 2;
}
int main() {
int a = return_int(); //works because return_int() is defined before it is used
cout << a;
}
1 2 3 4 5 6 7 8 9 10
int return_int();
int main() {
int a = return_int(); //works because prototype is defined before the function is used
cout << a;
}
int return_int() { //have to define the function somewhere
return 2;
}
On the subject of global variables...yes it very nice to be able to just do that, but eventually you are going to get into complex things where you are going to want many different variables, and having variables named: up, Up, uP, _UP, _up, etc isn't going to help very much...In you program it probably won't matter too much, but it is a good idea to not get into a bad habit.
Nope, all I have are <iostream> and <string> unless I am forgetting one somewhere. I have been working on this program over a week. It already has 11 functions, more are likely to be added b4 it is finished.
Thank you firedraco, I will clean those prototypes up. Do you have any clues as to why that for loop wont repeat?
I fixed it.
Seems I used the same variable "int c" in a for loop within the comp() function. No wonder I couldnt find the problem.
The program worked great, comp() ran perfectly, the only problem was that it would only run thru the battle loop once. I figure the problem had to be in this function.
Thanks for your help firedraco.
This will be my first real program. Real in the sence that I took more than an hour or 2 to write. I am very proud of it, and will be adding to planetsourcecode.com when I have finished it. Would it be againt to rules, or would any one object, if I add a link to it here in the forum's lounge?
Many of yall have, and I hope will continue, to help me with it. I would love to hear some feed back from all of yall, after it is complete. Anything you might be able to suggest that would help me write better/cleaner programs.
in places where you have used an 'if' conditional and there are only two possible conditions (i.e. greater than or less than) use an 'else' conditional instead of writing another 'if'.