Hi there.
There are a number of things that jump to mind first, and these aren't even solely C++ problems, but basic programming rules :)
To organize each case better I'll number each one and reference lines of code if necessary.
1. You have declared
int main ()
. Make sure that if you declare a function with a certain return type, that it actually returns the type you have declared it with. To clarify, since you declared
int
main(), main should return an integer! Best to stick with
return 0;
. Using 0 instead of any other number is generally good practice. A 0 represents successful execution, and 1 being an unsuccessful execution, possibly involving errors.
2. Your nested for-loops must have brackets around their bodies. Get in the habit of using brackets for logic statements and decision statements (if, else if, etc). In C++ you can only skip brackets if the body is 1 line.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// Take for instance these blocks, which assume you have
// some sentinel variable of num to which i counts to before
// stopping execution. In the body are some generically-named
// functions that do something as i increments. Pretty simple idea.
for (int i = 0; i < num; i++)
{
FunctionA(i);
FunctionB(i);
FunctionC(i);
}// Need brackets for multiple-line body
for (int i = 0; i < num; i++)
FunctionA(i);
// Don't need brackets for single-line body
|
3. You are referencing w like
Sum=+&w[3]
.
There are a couple issues here. An operator like "plus-assign" or
+=
always has the assignment operator appearing after the addition, subtraction, concatenation, or whatever. You got it right other times though with your
!=
and other
+=
's.
The other thing is that I think you're trying to reference w like an array...only it
isn't an array. It's defined in your code near the start of main as an
int
. Also when accessing an element in an array, use array_name[index]. By including the [index] you dereference the element at the given index location, so your ampersand
&
is unnecessary.
I think that's a good start for you to look at and start to work with. Beware though, this response is coming from a tired, full-time dude that should be going to bed about now. I could be blowing steam, hopefully if I do someone else will set you straight.
Cheers.