Hi!
I need support for this program, I have to do a homework and that’s about it, and I have no knowledge of c #. I have 4 errors:

Cannot implicitly convert type ‘double’ to ‘int’. An explicit conversion exists (are you missing a cast?) -> for h=0.01;
Division by constant zero -> for n=time/h;
Use of unassigned local variable ‘Y’ -> for E = V – Y[k];
Use of unassigned local variable ‘T’ – > for Console.Write( T[k + 1] = T[k] + h );

Basically, I need to represent the two lines in the for loop commented in the program. Any suggestions ?
class Program
{
static void Main(string[] args)
{
const int a = 3;
const int b = 2;
const int Kr = 5;
const int V = 1;
const int h = 0.01;
const int time = 1;
const int n = time / h; // 1/0.01=100
int[] Y;
int[] T;
Y[1] = 0;
T[1] = 0;
for (int k = 1; k < n; k++)
{
int E = V - Y[k];
int U = Kr * E;
// Y(k+1) = Y(k)+h*(-b*Y(k)+a*U);
// T(k+1) = T(k)+h;
Console.Write( Y[k + 1] + h * (-b * Y[k] + a * U) );
Console.Write( T[k + 1] = T[k] + h );
Console.WriteLine();
}
}
}

Those are very simple errors, and no I am not going to do your homework.
If it’s for homework, don’t you have books or materials for the class? Or a teacher you can ask?

No one here is gonna do your homework for you and to be honest those error messages are extremely self-explanatory if you had spent even a little bit of time trying to learn your class work.
what’s the reason for the conts’s? is that a requirement?

I will start by displaying those numbers, and therefore write this program correctly, in order to deal with some other requirements.
In C#, the data type int can only store whole numbers, to store decimal values you can use the double type like this: double h = 0.01; You would also need to change the type of ‘n’ to double as well as division returns a double. This will solve both the first and second errors. The third and fourth error is caused by you not initiating the array. You are only declaring it.

There is a difference between typing int[] Y; and int[] Y = new int[];. The first declares an array so that a reference exists but the array itself doesn’t. The second initiates an array such that an array exist but the array itself is empty.

I wrote it, now I have no errors, but I built it, then run and the terminal window opens for about a second then disappears. (it is a Console App (.NET Framework) project) .
static void Main(string[] args)
{
const int a = 3;
const int b = 2;
const int Kr = 5;
const int V = 1;
const double h = 0.01;
const int time = 1;
const double n = time / h; // 1/0.01=100
int[] Y;
Y = new int[105];
int[] T;
T = new int[105];
Y[1] = 0;
T[1] = 0;
for (int k = 1; k < n; k++)
{
int E = V - Y[k];
int U = Kr * E;
Console.Write( Y[k + 1] + h * (-b * Y[k] + a * U) );
Console.Write( T[k + 1] = (int) (T[k] + h));
Console.WriteLine();
}

I understand your corrections. For various reasons I couldn’t do more to learn C#, not even C, so I’m just an amateur.
Thanks for reply.

As has been said, all of those errors are very self explanatory, I don’t disagree with helping people in posts like this but cmon.
You could’ve answered your first error in less time than it took you to write this post by just googling data types, integers or double, this post screams “I don’t want to learn c#, I’ve been asked to do this and don’t understand so please do it for me.”

On top of this acting like a dick to the people telling you to actually go search these extremely basic errors just confirms my point.
You know you could have just not replied right? You literally could have just thought “nope I’m not doing his homework for him”.
But instead you have written 5 paragraphs just trying to tell people how great you are and how shit newbies are.
High five 🖐.

Are you one of them trolls everyone keeps talking about?
Everyone on their high horse talking about not doing your homework for you, acting like they don’t google anything and just read books all the all day 😀

Don’t copy and paste as if it is homework they could plagiarize check it .

You didn’t necessarily have to write a new program, I can handle it when I only get some advice from someone. 🙂
Thanks for reply.
Console.ReadLine()

Your code is more accurate, at the first program I had 0.15 and 0. I added Console.ReadLine (); outside the for loop to see those 100 values.
Next step is to build a graph, but now sleep because work is coming.
I actually like the consts in the original especially with math formulas

When I’m coding at work I don’t look for fully complete solutions to my problems, I break it down into chunks to figure out why my code isn’t working, which is something you learn by not being spoon fed code.

Op could’ve found answers to these individual errors within 5 minutes if instead of posting it here expecting someone to solve his problems for him he’d instead actually read the error messages, but now he doesn’t need to even try and learn because you just handed him an answer…

source