OK, so you havent worked out the placing of parameters into functions - thats a very fundemental thing. If you do look through most of the code on this site you'll find some examples of user made functions that have parameters, and how to return values (theres some hints in there you know!)
You've done pretty well, in fact you've already used some parameters and prebuilt functions, you just need to take the next step of making your own.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
I assume you are using Visual Studio 2005 or 2008.
Make a new Console Application, name it as you want but don't call it Product. Then add a new class Product to your solution.
Keep what you have in your Main method, it is good!(well I would do it different, but then again who am I?)
So your ReadInput method should be in the Product class you added and it should fill some fields from that class like ProductName, UnitPrice etc.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
I will be more than happy if you help me with one or two of the variables so I can fill out the rest and post it back here. I have trying this for days and I am not not use to C# at all. Frustrating :-)
That sounds like someone whos coded in something else? Is this the case?
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Well if you were going to do that you would need to pass product to your read input, as well as then having properties you would read it into.
Which goes back to my earlier questions
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
OK, under ASP you'd most likely have used vb, did you ever make subs then?
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
OK, but how would you have made a sub in vb, to send it say 2 parameters, and return the sum of them as a result?
(c# while different is not as hugely different in this respect)
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Perhaps it is something like this you want?
Will this clarify your mind?
class Product
{
public string ReadName; //name of the product
//other fields here
public void ReadInput()
{
Console.Write(" Product name: ");
string ReadName = Console.ReadLine();
//other things here
}
//other methods here
}
class MyConsoleApp
{
static void Main(string[] args)
{
Product objGet = new Product();
objGet.ReadInput();
//now here I can use
Console.WriteLine("Name of product : {0}", objGet.ReadName);
Console.ReadLine();
}
}
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
That is totaly my fault! Not yours!
public void ReadInput()
{
Console.Write(" Product name: ");
string ReadName = Console.ReadLine();
Console.Write(" Product price: ");
double ReadPrice = Convert.ToDouble(Console.ReadLine());
Console.Write(" Unit count: ");
int UnitCount = Convert.ToInt32(Console.ReadLine());
Console.Write(" Food item y/n: ");
string FoodItem = Console.ReadLine();
}
Can you see why?
I redefined ReadName as alocal string variable of the method ReadInput!
Console.Write(" Product name: ");
string ReadName = Console.ReadLine();
should be
Console.Write(" Product name: ");
ReadName = Console.ReadLine();
do the same for the rest of your variables.
Sorry for the trouble, but do you know the definition of an expert?
An expert is a person who has made all the possible mistakes...
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Torbjorn, feel free to come back with your questions. Mark this thread as solved if you want.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661