Newbie problem

This is a discussion on Newbie problem within the C# Programming forums, part of the General Programming Boards category; decimal PI = 3.14159M; int radius = 4; decimal circumfere; int diameter; diameter = 2 * radius; circumfere = PI ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    8

    Newbie problem

    decimal PI = 3.14159M;
    int radius = 4;
    decimal circumfere;
    int diameter;


    diameter = 2 * radius;
    circumfere = PI * diameter;

    Console.WriteLine("The circumference is : ", circumfere);



    Its a program to calculate the circumference of a circle on c# Console application, it only displays "The circumference is : " and nothing else..

    can one of you help me?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    Console.WriteLine("The circumference is : " + circumfere);
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    8
    Quote Originally Posted by Magos View Post
    Code:
    Console.WriteLine("The circumference is : " + circumfere);
    yea ok man thanx a bunch

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    For more complex strings, you'll find formatting easier. (Concatentation is fine in this case) Following your initial attempt:
    Code:
    Console.WriteLine("The circumference is : {0}", circumference);
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    >> For more complex strings, you'll find formatting easier. (Concatentation is fine in this case) Following your initial attempt:

    True, but it's error prone and a pain to make changes. I would use the concatenation approach in every case, personally.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by Sebastiani View Post
    >> For more complex strings, you'll find formatting easier. (Concatentation is fine in this case) Following your initial attempt:

    True, but it's error prone and a pain to make changes. I would use the concatenation approach in every case, personally.
    String.Format() has an additional advantage that it also makes internationalization easier. There are some cases where concatention != format strings, such as:
    Code:
    String.Format("{0} cat", color == Color.Black ? "black" : "blue")
    Had you used concatentation, i18n would have been much harder. With format strings, we need only change the string literals in this (and most) cases. In french for example:
    Code:
    String.Format("char {0}", color == Color.Black ? "noir" ? "bleu")
    Additionally, I find that for longer strings, format strings generally increase readability.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    8
    k i understand the difference betwen using commas and the concatenation sign now thanx a bunch although I havn't gotten to string formatting yet ( last post)...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  2. Newbie problem with scanf function...
    By Mithal in forum C Programming
    Replies: 1
    Last Post: 11-13-2005, 09:28 PM
  3. Newbie ... looping problem
    By StupidIntel in forum C++ Programming
    Replies: 12
    Last Post: 05-13-2004, 06:45 PM
  4. Problem with code (newbie question)
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2002, 01:39 AM
  5. newbie coding problem
    By rippascal in forum C++ Programming
    Replies: 10
    Last Post: 01-08-2002, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21