Hi,
I am just now becoming exposed to C++ (ForDummies book)and programming in general and I'm confused on how to properly use headers and multiple source files. At this stage in writing this project I'me working on, I only have one of a few functions I'll be using. I have:
When I run the console, regardless of the Date I enter, the value "0" is returned. I suspect there may be multiple errors here, but could you help me understand what isn't going the way I think it should be? Could you point out what's not happening from my thought process?
My thought process:
The function WeekNumberFunction is located in a source file not in main. A header is being used so that main is aware of it. I use this function in main to return a value to WeekNumber (1-5) based on the Date.
Thank you for your time.
P.S.
If you have any recommendations on how to approach learning C++ for an absolute beginner, it would be appreciated.
Thanks, I understand what your saying, but, Zhuge, should I:
1)replace all the declarations for the int WeekNumber with extern int WeekNumber
or
2)replace all the declarations for the function int WeekNumberFunction () with extern int WeekNumberFunction () ?
Also, your post ("if you really want to do it this way")suggests that there is a better way of doing this. Is there a better way?
Pass the variable as an argument. Also, if (7>Date>1) &c won't do what you think it does. You'll need to do something like this: if(7 > Date && Date > 1)
in C++, you can only compare two things at a time basically.. so you first have to determine that (7 > Date) /*that 7 is greater than Date*/ && /*and*/ (Date > 1) /* that Date is greater than 1*/
What they are saying is you have 2 different variables in your program called WeekNumber, and two variables inaccessible by your function called Date and Month.
By passing the variables as arguments, you define the variables once, and then tell the function what those variables are by passing them as arguments.