Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
Just need some help with a simple code, maybe not so simple.
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
A X
11y
1.2k
1
Reply
I almost got it but im having trouble with the finishing touch. i want to create a method that subtracts 3 from 3 numbers inputted by the user and show them at the end of the program. it tells me that x is unassigned but when i declare it inside the method it tells me there is a 'parent' use of the variable, whats going wrong here.......any help or tips would be soo appreciated. thank you in advance.
Here is what I have so far.......
class Program
{
static void Main(string[] args)
{
int x;
int []a = new int[3];
for (x = 0; x < 3; x++)
{
Console.Write("enter number = "+ x);
a[x] = Int32.Parse(Console.ReadLine());
}
method(a);
}
static void method(int[] a)
{
for (int x = x - 3; x < 3; x++) //****my problem is here...where i put "int x = x - 3" // the program tells me that "use of unassigned local // variable x" what does that mean? when i try to // declare it inside the method it gives me
// more errors, why? and how do i fix it?
{
Console.Writeline("first number subtracted by 3 ~~> " + x);
}
}
}
}
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
how to work with authentication certificates?
how to windoservice restart after service failed in c# .net?