Windows application to sum two numbers

advertisement
Console Application to Sum Two Numbers
1. Create the new project.
a. Open Visual Studio .NET, and select File > New > Project… >
Visual C# Projects.
b. Select Console Application in templates window
c. Name the project SumNos and select a directory in which to save the
project.
d. Click OK. Visual Studio.Net will load the new solution and a console
application template
2. Rename the source code file.
a. Double-click the Solution Explorer in the toolbar or select
View > Solution Explorer.
b. Select Class1.cs, rename to SumNos.cs.
c. Replace all occurrences of Class1 in the template with SumNos.
3. Create application logic.
a. Delete comments from template
b. Following header:
static void main( string[] args)
insert the following code.
string firstNumber,
secondNumber;
int number1,
number2,
sum;
// first string entered by user
// second string entered by user
// first add operand
// second add operand
// sum of the two integers
// prompt user for first integer, then read its value from keyboard
Console.Write("Enter the first integerr: ");
firstNumber = Console.ReadLine();
// prompt user for second integer, then read its value from keyboard
Console.Write("Enter the second number: ");
secondNumber = Console.ReadLine();
// convert string form of integers into 32-bit integers
number1 = Int32.Parse( firstNumber);
number2 = Int32.Parse( secondNumber);
// add the two integers
sum = number1 + number2;
// display sum on the monitor
Console.WriteLine("\nThe sum is {0}.",sum);
4. Save the project ( File > Save all)
5. Compile the program
a. On menu bar select Build > Build Solution
b. The program will be compiled and display error messages (if any) in an
inset window.
6. Run the program
a. On menu bar select Debug > Start without debugging
b.. Execution results will be displayed in a black window
7. Print the results
a. select the output
b. copy the output to the desktop
c. paste the output into WordPad or other editor that accepts graphical
elements
d. print the document
Download