Reading integers from user
How do you read ints from a user if i have
int num1;
int num2;
int sum;
sum = num1 + num2;
How do i enter number without the error saying the varibles num1 , 2 are not assigned i know they are empty but i want them that way...If i assign and x and y value then it gives me the error saying they are not apart of the class? Any Help? Observers in the forum seem to think this an introductory problem but i have yet to get a answer to put me on the right track?
[542 byte] By [
Dpowers] at [2007-12-16]
You have posted C# code in a VB forum. Integer variables are initialised to zero by default in VB. In C#, the first operation you perform on a variable must be an assignment. If you need to use the variables in a calculation or pass them to a method, I suggest that you initialise them to zero yourself first.
Assuming you want vb code, then assign a value on declaration.
Dim Num1 as Integer = 0
If you're using C# or C++, wrong forum.
Hi,
Ok, I got confused about your inquiry there. Could you be more specific? What do you mean by enter? User input? could you post a code snippet or a steps to reproduce what you are trying to do? In that way we could help you a little bit faster...

cheers,
Paul June A. Domag
Are you talking about the warnings that are provided to you in the editor code window
If so you have a number of options
one is to assign a value when you dim the variables
so
Dim num1 as integer = 0
Dim num2 as integer = 0
dim Sum as integer = 0
This will prevent the warnings from showing under the variable telling you that unused local variable: 'num1' etc.
You can turn these warnings off for the project if you want - or even make then errors by going to the Solution Explorer
My Project / Compile and you will see a data grid showing the various types of warnings. The notification can be set to None / Warning or Error setting them to none will mean that you will not be shown this warning anymore and can simply
use
Dim Num1 as integer
Dim Num2 as integer
Dim Sum as integer
without generating any warnings.