4 Replies - 385 Views - Last Post: 02 September 2012 - 09:15 PM Rate Topic: -----

#1 ecarter202  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 02-September 12

Rounding decimal to whole number.

Posted 02 September 2012 - 09:05 PM

This program works, just rounding the decimal to a whole number. I've tried String.Format & Math.Round. Didn't work however I did it. ha. Please Help!!

using System;

class Program
{
    static void Main()
    {
        int w; // Radius of Circle
        int x; // Side of the Square * 2
        int y; // Area of the Square
        decimal z; // Radius squared

        Console.WriteLine("Enter the circle's radius: ");
        w = int.Parse(Console.ReadLine());

        x = w * 2;
        y = x * x;
        z = w * w * 3.14m;
        z = Math.Round(z, 2);

        Console.WriteLine("The shaded area is: " + (y - z));


        Console.ReadLine();
    }

}


Is This A Good Question/Topic? 0
  • +

Replies To: Rounding decimal to whole number.

#2 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:07 PM

"It didn't work" doesn't tell us what happened.

What input did you give, what results did you get, and what results did you expect?
Was This Post Helpful? 0
  • +
  • -

#3 ecarter202  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 02-September 12

Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:09 PM

Sorry. Just figured you'd attempt it yourself. I put in 10 and it should print 85.8 something. But it prints out 86.00.
Was This Post Helpful? 0
  • +
  • -

#4 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:12 PM

1) Never assume we're going to do your work for you.

2) Look at your math. If you input 10, you're doing:
w = 10
x = w * 2 = 10 * 2 = 20
y = x * x = 20 * 20 = 400
z = w * w * 3.14 = 10 * 10 * 3.14 = 100 * 3.14 = 314
z = Round(z, 2) = Round(314, 2) = 314


Then you're printing
y - z = 400 - 314 = 86

This post has been edited by Mina-no-Hime: 02 September 2012 - 09:13 PM

Was This Post Helpful? 0
  • +
  • -

#5 ecarter202  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 02-September 12

Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:15 PM

okay. i feel like a damn retard; but happy that it actually works.

thank you for letting me waste some of your time this evening.
and sorry.
Was This Post Helpful? -1
  • +
  • -

Page 1 of 1