Hi sphstctd,
Sorry if I sounded grumpy earlier, but occasionally we get some time wasters here.
So, some advice:
Have a look at the tutorial at the top left of this page, there is also lots of reference material & articles.
With your program, if you make
dx
a
double
there will still be problems, because types are implicitly cast (promoted) according to a set of rules. For example
y[i]*dx
, would be
int
multiplied by
double
which is
double
, so
y[i] - y[i]*dx
is also
double
, but
y[i+1]
is expecting an
int
.
To solve this, make the arrays
double
, but their sizes as
int
, and leave the for loop counter as
int
because each of the variables on line 7 have to be of an integral type.
One huge lesson is to
ALWAYS Initialise your variables with something. This can be one of the biggest source of errors - especially for beginners.
Style wise it is a really good idea to always declare & initialise and comment one variable per line. Give variables meaningful names, provide comments about expected range of values - value must be positive as an example. The main thing is to be as clear as possible with your code.
For beginners, I would recommend that you learn things in this order:
> Learn to write pseudo-code - a recipe or methodology as comments to guide you when writing code.
> Understand all the different basic types (int, short, long, char, double, float ) and their qualifiers (unsigned, const), what their ranges are (max, min values), what their precision is, how to declare them, how to assign values to them, how to declare & assign in one statement, how to print them with
std::cout
, how to read them in with
std::cin
, and how they are stored, and what one can and can't do with them, how they are promoted, and how one can change the type of the copy of their value by casting.
> Understand the different operators, what types they can be used with, and why some are better than others. For example
a++
is better than
a = a + 1;
, and
a+=10;
is better than
a = a + 10;
for integral types. Also understand the different groups of operators: assignment, increment / decrement, comparison, mathematical, binary
> Understand what the different types of expressions are. As an example a
for
loop is this:
1 2 3
|
for (assignment ; conditional ; increment) {
statements
}
|
> Understand compound statements.
> Understand the control-flow features like if (
conditional) {} else if (
conditional){} else {}, switch statements, loops.
> Understand arrays, how to make them with different types, make with 2 dimensions, initialise them, retrieve values from, assign values to individual elements, copy them.
> Understand functions, what are parameters & arguments, how & where to declare & define them, return types, pass references to .
All this might look a bit technical to you right now, but it really only scratches the surface.
Hope all goes well, and look forward to seeing your code + answering any questions you might have.