-1

Im creating an two dimensional array and giving the user the chance to set there double variables. When i want to print out the result, it is shown without points exp: user entry 3.45 -> 345 Conver.ToDouble doesnt function neither the following code shows my "programm" nevermind exception handling

static void Main(string[] args)
{  
    double[,] Array = new double[,] { { 0, 0, 0}, { 0, 0, 0 }, { 0, 0, 0 } };
    array Object = new array();
    array[0,0] = Double.Parse(Console.ReadLine()); 
    Console.WriteLine("Wert  = {0}",intArray[0,0]);
    Console.ReadKey();
    }
}
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • 3
    Your sample code wouldn't even compile - and it's unclear why you're asking for user input, either. Please give a short but complete program which really demonstrates your problem. – Jon Skeet Dec 10 '13 at 17:39
  • There's a few issues with the sample you provided: your declarations are invalid. You seem to be confusing data types with identifiers (`array Object = new array()` ) and you have a variable named intArray in your WriteLine statement that hasn't been declared anywhere else. – Reacher Gilt Dec 10 '13 at 17:43
  • sorry for the disorder i created. the code had a lot of mistakes because i tried to cut it for posting it here. 3,5 was only an example to show you how the number is displayed afterwards. even if theres no compile error as i had it before or as Shaharyar corrected it, the programm prints the double variable without a point (3,45 -> 345) i dont get it why – user3087913 Dec 10 '13 at 18:51
  • One thought: given the `intArray` name, are you perhaps casting/converting to an integer somewhere? – Joel Coehoorn Dec 10 '13 at 19:42
  • no the name was for something tried before. i definately just use double formats – user3087913 Dec 10 '13 at 19:53

2 Answers2

0

Multiply the values by 100, and then use the following format string:

Console.WriteLine("Wert  = {0:F0}",intArray[0,0] * 100);
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • that's not going to help. Hint: Where is intArray declared? Even then, he's asking to get the decimal value printed, which your suggestion does not do. – Reacher Gilt Dec 10 '13 at 17:43
  • @ReacherGilt It answers the display issue. More than that would just give him code without helping him learn, which is something the OP needs. – Joel Coehoorn Dec 10 '13 at 17:45
  • Can you help me understand how your sample will print,ex., `3.45` as the question asks? I don't see it. – Reacher Gilt Dec 10 '13 at 17:47
  • @ReacherGilt My understanding of his prose is that the user enters 3.45, and he wants to show 345 – Joel Coehoorn Dec 10 '13 at 17:49
  • sorry for the disorder i created. the code had a lot of mistakes because i tried to cut it for posting it here. 3,5 was only an example to show you how the number is displayed afterwards. even if theres no compile error as i had it before or as Shaharyar corrected it, the programm prints the double variable without a point (3,45 -> 345) i dont get it why ... – user3087913 Dec 10 '13 at 18:41
0

Your code has a lot of errors as I found:

corrected code is:

static void Main(string[] args)
        {  
            double[,] Array = new double[,] { { 0, 0, 0}, { 0, 0, 0 }, { 0, 0, 0 } };
            //array Object = new array(); //no need of this because you are not using it any where
            Array[0,0] = Double.Parse(Console.ReadLine()); //"array" doesn't exist, it should be "Array"
            Console.WriteLine("Wert  = {0}",Array[0,0]); //"intArray" has not been initialized, it should be "Array" in you case
            Console.ReadKey();
        }

Here is the output:

enter image description here

I hope it will work now.

Shaharyar
  • 12,254
  • 4
  • 46
  • 66
  • thanks! unfortunately i made the mistakes during my try to cut the code for posting it here. so i had quite the same version as you corrected it. but the number is still displayed without the point. – user3087913 Dec 10 '13 at 18:43
  • @user3087913 See the output I've attached, i think you are making any other mistake – Shaharyar Dec 10 '13 at 19:07
  • i copy pasted your version in an extra project and it printed it without the point oO Maybe theres something wrong with the visual studio setup? but than it shouldnt be the first time the problem accrued – user3087913 Dec 10 '13 at 19:09