learning to read the error messages is useful. I recommend to beginners that once you fix the error, you re-read the message and try to see if you can grasp what it was telling you. A starting place is that the line number will be given: what line has that error message, and what was before it? You may have missed a ;.
I don't get the same errors you did, is it the same code?
anyway, lets start slowly.
- your functions do not DO anything.
- getSum refers to 'number' which is a LOCAL variable to main; there IS NO SUCH variable at this "SCOPE" -- the compiler can't find it!
- you asked about a parameter, but have none.
- the product one is factorial and will blow out even a double after a short while (too big to fit). Don't worry about this, just use smaller numbers for now.
I would comment out product for now and get sum working.
try these ideas:
1 2 3 4 5 6 7 8 9
|
double getSum(int number); //fix the header part
double getSum(int number);
{
double total = 0.0;
for(int i = 1; i <= number; i++)
total+=i;
return total;
}
| |
the sum from 1 to N can just be directly computed with a formula, but that is math, not programming, and you can check out doing it that way later.
https://en.wikipedia.org/wiki/1_%2B_2_%2B_3_%2B_4_%2B_%E2%8B%AF
if you cannot change the while loop in main (that seems wrong?) then what is getSum supposed to DO? The loop is adding up something. All getsum would do is increment a static variable, as written:
double getsum()
{
static double derp = 0;
derp +=1;
return derp;
} //returns 1, 2, 3, 4, 5,...
or are you doing the 1 to N for 1, then again for 2, then again for 3, ..? Its really unclear.