General Summation Program (Looking For Experienced People Also)

If you can solve this for me, message me for inquiry if you are interested in programming a few simple programs for money.

I can't wrap my head around a lot of programming concepts.

I need to find the summation of two numbers with an option to choose an increment to go up by.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
private: System::Void btnCalculate_Click(System::Object^  sender, System::EventArgs^  e)
			 {
				 // Declare Variables
				 int first;
				 int last;
				 int step;
				 int sum = 0;

				 // Read Inputs
				 Int32::TryParse(txtFirst->Text, first);
				 Int32::TryParse(txtLast->Text, last);
				 Int32::TryParse(txtStep->Text, step);

				 // Calculate The Data
				 if ((first < last) && (step < 0))
					 MessageBox::Show("Invalid Step.");
				 else if
					 ((first > last) && (step > 0))
					 MessageBox::Show("Invalid Step.");
				 else if
					 ((first > last) && (step > 0))
				 {
					 for (int counter = first; counter <= last; counter += step)
					 sum += counter;
					 txtSum->Text = sum.ToString();
				 }
				 else if
					 ((first < last) && (step < 0))
				 {
					 for (int counter = first; counter <= last; counter += step)
					 sum += counter;
					 txtSum->Text = sum.ToString();
				 }




				 else
				 {
					 for (int counter = first; counter <= last; counter++)
					 sum += counter;
					 txtSum->Text = sum.ToString();
				 }

			 }
};
}
bump
Topic archived. No new replies allowed.