How should I approach this assignment? Should I use an if/else statement?
Assignment 1:
Write a Windows application that accepts any number of positive values.
The user clicks a button to process all the inputted data at any time. The resulting output:
- sum of all the n entered numbers, followed by n rows, displayed in the order of input:
- the original inputted number;
- the percentage contributed by this number to the sum.
Though I don’t understand the project in entirety. This should at least point you in a solid direction.
At this point your project will open with a canvas, in designer mode. To help describe what is happening
clicktheFormonce.On the right-hand side of your Window you will see
Solution ExplorerandProperties.Solution Explorer: This will show you the contents of your project. It contains the following:
Assembly,Resource, andSettingsinformation.Assembliesthat help expand your project or link to other applications you may be doing.The next item, is going to be your
Form. This is the most important part; because this will be where all your manipulation will be.Now the second item I mentioned;
Properties. Not the one inSolution Explorerbut the tab that stands apart. Will show you all the modifications for that component. In this case, yourForm.On the left-hand side what you’ll do is actually go to
Toolbox. These are all the components that Microsoft provides you right out of the gate. Simply drag theTextboxComponent out of theToolboxonto yourForm(canvas).You’ll notice the outline, with several
transformationdots for you to manipulate location and dimensions.Before we move further I’ll break it down what has happened. You’ve input a blank
textboxonto yourForm. By default it will be calledTextBox1. It is good practice to identify the component with what it is then it’s desired function. If your looking for lets say a users first name, name ittxtFirst. That way it is easier to understand what your manipulating.Since my goal is to help point you in the right direction, follow these steps:
Label– Name itlblInput(Change text to name of your choice).Textbox– Name ittxtInput.Rich Textbox– Name itrtxtDisplay.Now these three components will inherently be your
User Interface. All of the interaction will occur here. But we are missing oneElementto the interface. A button, this is important because it will create what is called anEvent. These will essentially notify the interface of a change so it appears that it is doing something.Buttonout of the Toolbox, name isbtnAdd.Now you have an entire interface; so now double click on the button. Your screen will now change; you’ll see all of this text.
The important part is where it navigated you to by selecting the button.
So that will provide you the
Eventso you can perform your logic to create your application. Now, I’m not going to do your code for you. But I’ll do something close so you can adapt and learn.So as you can see the
//and/*are different methods to comment to make your logic easy to understand. I’m using it to explain what is happening for you. ThetxtInput.Texttakes whatever inputstringvalue and is now beingcastedto aninteger.Now, this will actually allocate a reference in your memory. Which will allow you to store multiple things into the
Array. This method would work well if you pass all yourtextboxinput into yourRich Textbox. Then a second button could fill the array to add each item.In this example I will actually write an entire aspect but as I stated you’ll need to do certain things to make it meet your needs.
There is half your battle right there. Things to help you truly understand this conceptually, will be these items to help you complete your project.
CastingArraysGenericsLoopsHopefully that helps you. Those are some basic lessons; I might suggest the entry level tutorial courses on MSDN.