What am i missing in my code. Because it is not working.
According to visual studio, the istartd and iendd are unassigned local variable.
Console.WriteLine("{0, 40}", "Sphere Surface Area Evaluator");
Console.Write("\nEvaluates Surface areas of spheres of various diameter");
do
{
try
{
bError = false;
Console.Write("\nEnter the starting diameter for the spheres: ");
istartd = int.Parse(Console.ReadLine());
if (istartd < 0)
{
Console.WriteLine("The start value must be positive.");
bError = true;
}
}
catch (FormatException)
{
Console.WriteLine("An incorrect diameter was entered.");
bError = true;
}
finally
{
Console.WriteLine("");
bError = true;
}
do
{
try
{
bError = false;
Console.Write("\nEnter the end diameter for the spheres: ");
iendd = int.Parse(Console.ReadLine());
if (iendd < istartd)
{
Console.WriteLine("The end value must be positive and greater than the start value.");
bError = true;
}
}
catch (FormatException)
{
Console.WriteLine("An incorrect diameter was entered.");
bError = true;
}
finally
{
Console.WriteLine("");
bError = true;
}
}
while (bError);
}
while (bError);
for (int iX = istartd; iX <= iendd; ++iX)
{
dA = 4 * 3.14159 * Math.Sqrt(istartd / 2);
Console.WriteLine("A = {0} , d = {1}", dA, iX);
}
Console.WriteLine("Press any key to continue");
COnsole.Read();
The program should look like this.
Sphere Surface Area Evaluator
Evaluates Surface areas of spheres of various diameter
Enter the starting diameter for the spheres: cats
An incorrect diameter was entered.
Enter the starting diameter for the spheres: -2
The start value must be positive.
Enter the starting diameter for the spheres: 2
Enter the end diameter for the spheres: -2
The end value must be positive and greater than the start value.
Enter the starting diameter for the spheres: 6
A = 12.6 , d = 2
A = 28.3 , d = 3
A = 50.3 , d = 4
A = 78.5 , d = 5
A = 113.1 , d = 6
Press any key to continue