3.5. Adding Integers

Our next program (Fig. 3.16) inputs two integers (whole numbers) entered at the keyboard by a user, computes the sum of these integers and displays the result. As the user enters each integer and presses the Enter key, the integer is read into the program and added to the total.

Figure 3.16. Addition program that adds two integers entered by the user.
					1
					' Fig. 3.16: Addition.vb
					2
					' Addition program.
					3
					4
					Module Addition
 5
					6
					Sub Main()
 7
					8
					' variables used in the addition calculation
					9
					Dim number1 As Integer
					
					10
					Dim number2 As Integer
					
					11
					Dim total As Integer
					
					12
					13
					' prompt for and read the first number from the user
					14
					Console.Write("Please enter the first integer:")    
					15
					number1 = Console.ReadLine()                        
					16
					17
					' prompt for ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.