Of course not. But it's overkill for someone who hasn't mastered functions.
First one must grasp the basics, then move on to more advanced things.
Printable View
Of course not. But it's overkill for someone who hasn't mastered functions.
First one must grasp the basics, then move on to more advanced things.
You probably need to move your declarations (e.g. "int tableAnswer" & "int firstNumber") outside of main(), since main() is not the only function using those variables, and that's because you would otherwise have to declare them in "void()" as well, and it's easier to call globals, as long as it's relevant.
Then, you should think about using the "int getNumber()" function to place the input number into a variable, and making "firstNumber" equal that variable, instead of equaling the function itself. If you have an "int" function, it should usually return 0 at the end.
Third, put the variable you want to pass into the "void" prototype at the top, because otherwise it's too vague.
Then, with everything being done in the called functions, all you have to do is call the functions in main, and provide for the system pause.
Of course, being a noob myself, I could have gotten some of the info wrong, so if any more experienced programmers out there find something wrong with my suggestions, please, correct me. I don't want to contribute to the delinquency of a programmer:D
@Elysia: However unfortunate it might be, and however right you may be, using the functions is part of the assignment, and he doesn't have enough time to put it together without using functions and then re-write it in function format.
NO! Avoid global variables. Pass by argument instead.
Not really. Each function should return whatever that function may need to do, depending on the situation. Just because it takes and int doesn't mean it should return an int.
This is if I'm reading you correctly.
Yes, the biggest error is "avoid global variables." Unless you have a very, very good reason to use them, then don't. Pass by argument instead.
First: optional arguments is not required for this excercise as far as I see.
And second: We are not here to do homework for them, but to assist them. If we provide all the code, then they won't learn.
Why is that so big?
Global variables makes your code prone to errors. Anyone would tell you to avoid them ;)
So, can you pass variables into "int" functions?
And, would you say it's better to declare function prototypes or to simply put those functions before the functions that would call them?
Declarations should always go into the header files and included where the functions needs to be used/called.