Nooby question but can anyone help me out?

I'm taking an Intro to Programming class and they're teaching C#. It's good, I'm enjoying the language and doing really well in the class but I've been having a ton of trouble with the most recent lab.

Basically it's a series calculator. There are three inputs: start, end and step. The calculator first has to add the "step" value to the "start" value until it hits the "end" value. That's fine, I've got that bit working.

There are two issues though. The first is that after it's done all that, the calculator needs to either add or multiply each step together, giving the result. The second is that it needs to be able to do all this with both positive and negative step values.

Right now my code for it looks like this:

if (AddRadio.Checked == true) { int Count = Start; if (Step > 0) { while (Start + Step <= End) { Start += Step; Count += Start; } ResultLbl.Text = "Result: " + Convert.ToString(Count); } } if (Step < 0) { int Count = Start; while (End < Start) { Start += Step; Count += Start; } ResultLbl.Text = "Result: " + Convert.ToString(Count); } } if (MultiplyRadio.Checked == true) { int Count = Start; if (Step > 0) { while (Start + Step <= End) { Start += Step; Count = Start * Count; } } ResultLbl.Text = "Result: " + Convert.ToString(Count); } if (Step < 0) { int Count = Start; while (End < Start) { Start += Step; Count = Start * Count; } ResultLbl.Text = "Result: " + Convert.ToString(Count); } } 

Before that, I’ve defined variables for Start, End and Step and I’ve included checks for valid input.

I’m really not looking for someone to do my homework here. But our teacher isn’t helping very much so if you’d be able to point me in the right direction I’d be eternally grateful.

(Also figured I should included some sample values, incase it’s useful.

if Start = 2 End = 12 Step = 3

Then the result (if adding) should be 32.

if Start = 1 End = 10 Step = 4

Then the result (if multiplying) should be 45.)

by punkrok97 via /r/csharp

Leave a Reply