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();
}
}
Rounding decimal to whole number.
Page 1 of 14 Replies - 385 Views - Last Post: 02 September 2012 - 09:15 PM
#1
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!!
Replies To: Rounding decimal to whole number.
#2
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?
What input did you give, what results did you get, and what results did you expect?
#3
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.
#4
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:
Then you're printing
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
#5
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.
thank you for letting me waste some of your time this evening.
and sorry.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|