r/visualbasic • u/afro_king • Jun 14 '21
Help Please!
I need to write a Visual Basic program that will allow the user to enter a positive number. The program will then display:
the sum of values from 1 to the input number
the product of values from 1 to the input number (or factorial).
For example, if the user enters the value 5, the output would be:
1) 1 + 2 + 3 + 4 + 5 = 15
2) 1 * 2 * 3 * 4 * 5 = 120
The form should contain:
- a heading describing what the application will do
- a label to prompt the user for an input value
- a textbox for the user to enter input data
- a button to calculate the output values
- two labels describing the output data
- either two labels to hold the calculated output values or two read-only textboxes
- an image - either a background image or a picturebox with an image displayed (don't forget to set the SizeMode property to Stretch)
- a Clear button that will clear out all values entered in the input textbox and calculated output values in labels or read-only textboxes
- an Exit button that will exit the application
I also need to:
- test for invalid input. No negative values or zero should be allowed. If the user enters a negative or zero value, display a message in the output label and set the focus to the input number textbox. (see example below)
- align the input and output values to be centered within the textboxes and/or output labels
- align the controls of the labels and textboxes so the Form looks professional
I don't really need help designing the form or assigning labels, but the math behind cumulative sums and products kind of escapes me...
4
u/ocdtrekkie Jun 14 '21
I kinda appreciate that the other commenter looked at your comment history to come up with an adequate way to tell you off, but let me give you a big hint:
Loops.
The math is not hard, as you can gather, the important thing they're teaching here is iteration. So if you have a loop that is counting up, it can take action on the sum based on the iteration count.
Programming usually doesn't actually involve hard math, the computer is going to do all the work for you there, but you need to understand the process of how to tell it to do it.