Discussion:
how do you read in an integer in a console application?
(too old to reply)
g***@gmail.com
2015-02-11 14:13:16 UTC
Permalink
i don't know the syntax for visual basic:

prompt user to enter number1
read in number1
prompt user to enter number2
read in number2

so.

Dim number1 As Integer
Dim number2 As Integer

Dim Sum As Integer

Console.WriteLine("Enter first number: ")
'what is the command to read in a number for console application

Console.WriteLine("Enter second number: ")
'what is the command to read in a number for console application

sum = number1 + number2

'what is the command to display the sum for console application
Console.WriteLine( sum )

thanks, i trying to learn vb

g.
G G
2015-02-11 15:13:27 UTC
Permalink
Post by g***@gmail.com
prompt user to enter number1
read in number1
prompt user to enter number2
read in number2
so.
Dim number1 As Integer
Dim number2 As Integer
Dim Sum As Integer
Console.WriteLine("Enter first number: ")
'what is the command to read in a number for a console application
Console.WriteLine("Enter second number: ")
'what is the command to read in a number for a console application
sum = number1 + number2
'what is the command to display the sum for a console application
Console.WriteLine( sum )
thanks, i'm trying to learn vb
g.
thanks.
g.
Deanna Earley
2015-02-11 15:24:32 UTC
Permalink
Post by g***@gmail.com
prompt user to enter number1
read in number1
prompt user to enter number2
read in number2
so.
Dim number1 As Integer
Dim number2 As Integer
Dim Sum As Integer
Console.WriteLine("Enter first number: ")
'what is the command to read in a number for console application
Console.WriteLine("Enter second number: ")
'what is the command to read in a number for console application
sum = number1 + number2
'what is the command to display the sum for console application
Console.WriteLine( sum )
thanks, i trying to learn vb
Assuming you mean VB.NET, try Console.ReadLine() and Integer.Parse()
--
Deanna Earley (***@earlsoft.co.uk, ***@doesnotcompute.co.uk)

(Replies direct to my email address will be printed, shredded then fed
to the rats. Please reply to the group.)
G G
2015-02-12 03:23:38 UTC
Permalink
Post by Deanna Earley
Assuming you mean VB.NET, try Console.ReadLine() and Integer.Parse()
********************************************************************************

' ----------- declare variable -----------

Dim stringToBeA_Number As String
Dim number1 As Integer
Dim number2 As Integer
Dim sum As Integer

'---------prompt user for input and read in first value --------

Console.WriteLine("Enter first value: ")
stringToBeA_Number = Console.ReadLine()

'-------- convert string to an integer and store in number1 -------
number1 = Integer.Parse( stringToBeA_Number )

'--------- convert string to an integer and store in number2 ------
Console.WriteLine("Enter first value: ")
stringToBeA_Number = Console.ReadLine()

'-------- convert string to number and store in number2 -------
number2 = Integer.Parse( stringToBeA_Number )


'------------- calculate sum -------------

sum = number1 + number2

'-------------- display sum ---------------

Console.WriteLine( "The sum is " + sum )


********************************************************************************

thanks Deanna, i hope that's right.
G G
2015-02-12 03:28:57 UTC
Permalink
Post by Deanna Earley
Assuming you mean VB.NET, try Console.ReadLine() and Integer.Parse()
********************************************************************************

' ----------- declare variable -----------

Dim stringToBeA_Number As String
Dim number1 As Integer
Dim number2 As Integer
Dim sum As Integer

'---------prompt user for input and read in first value --------

Console.WriteLine("Enter first value: ")
stringToBeA_Number = Console.ReadLine()

'-------- convert string to an integer and store in number1 -------
number1 = Integer.Parse( stringToBeA_Number )

'--------- convert string to an integer and store in number2 ------
Console.WriteLine("Enter second value: ")
stringToBeA_Number = Console.ReadLine()

'-------- convert string to number and store in number2 -------
number2 = Integer.Parse( stringToBeA_Number )


'------------- calculate sum -------------

sum = number1 + number2

'-------------- display sum ---------------

Console.WriteLine( "The sum is " + sum )


********************************************************************************

thanks Deanna, i hope that's right.

Continue reading on narkive:
Loading...