This is a C program I attached the code I have so far but I
This is a C# program. I attached the code I have so far but I get a million errors when I debug it and I dont know how to fix it .. I dont know if its right in the slightest bit (Im extremely new to this language) but any help is greatly appreciated. Thank you soooo much!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project2AreaCalculator
{
class Program
{
public double result, l, h, s, w, d1, d2, b, r, lb, sb;
int option;
static void Main(string[] args)
{
Program a = new Program();
private static void CalculateCircle()
{
console.WriteLine(\"Please enter the radius of the circle\");
radius = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of Circle is:{0}\", 3.14 * radius * radius);
}
private static void CalculateSquare()
{
Console.WriteLine(\"Enter the side of a square\");
side = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of Square is:{0}\", side * side);
}
private static void CalculateRectangle()
{
Console.WriteLine(\"Enter the length of the rectangle\");
l = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the width of the rectangle\");
w = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of rectangle is :{0}\", l * w);
}
private static void CalculateRhombus()
{
Console.WriteLine(\"Enter thelength of one diagonal of the rhombus\");
d1 = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter thelength of other diagonal of the rhombus\");
d2 = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of the Rhombus is : {0}\", (d1 * d2) / 2);
}
private static void CalculateParallelogram()
{
Console.WriteLine(\"Enter the length of the base of the parallelogram\");
b = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the height of the base of the parallelogram\");
h = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of the Parallelogram is : {0}\", b * h);
}
private static void CalculateTrapezoid()
{
Console.WriteLine(\"Enter the length of the large base of the trapezoid\");
lb = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the length of the small base of the trapezoid\");
sb = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the height of the trapezoid\");
h = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of parallelogram is:{0}\", (lb + sb) * (h / 2));
}
Console.WriteLine(\"\ \ \");
Console.WriteLine(\"Shape Area Calculator:\ \");
Console.WriteLine(\"*****************************************************************\");
Console.WriteLine(\"\ \ \");
Console.WriteLine(\"Please select the number of the operation you would like to perform:\");
Console.WriteLine(\"1. Circle\");
Console.WriteLine(\"2. Square\");
Console.WriteLine(\"3. Rectangle\");
Console.WriteLine(\"4. Rhombus\");
Console.WriteLine(\"5. Parallelogram\");
Console.WriteLine(\"6. Trapezoid\");
Console.WriteLine(\"7. Exit\");
Console.WriteLine(\"\ \ \");
Console.WriteLine(\"********************************************************************\");
Console.WriteLine(\"Select a shape type to calculate : \");
option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Console.WriteLine(\"1\");
break;
case 2:
Console.WriteLine(\"2\");
break;
case 3:
Console.WriteLine(\"3\");
break;
case 4:
Console.WriteLine(\"4\");
break;
case 5:
Console.WriteLine(\"5\");
break;
case 6:
Console.WriteLine(\"6\");
break;
case 7:
Console.WriteLine(\"7\");
break;
console.ReadKey();
}
}
}
}
Solution
Here goes the working program.
*console is written instead of Console
*method definitions are moved out of the main method
*Variable declarations are made inside the method
*There was a problem with access specifiers as well. FIxed them.
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rextester
{
class Program
{
//public double result, l, h, side, w, d1, d2, b, radius, lb, sb;
//int option;
public static void Main(string[] args)
{
Program a = new Program();
Console.WriteLine(\"\ \ \");
Console.WriteLine(\"Shape Area Calculator:\ \");
Console.WriteLine(\"*****************************************************************\");
Console.WriteLine(\"\ \ \");
Console.WriteLine(\"Please select the number of the operation you would like to perform:\");
Console.WriteLine(\"1. Circle\");
Console.WriteLine(\"2. Square\");
Console.WriteLine(\"3. Rectangle\");
Console.WriteLine(\"4. Rhombus\");
Console.WriteLine(\"5. Parallelogram\");
Console.WriteLine(\"6. Trapezoid\");
Console.WriteLine(\"7. Exit\");
Console.WriteLine(\"\ \ \");
Console.WriteLine(\"********************************************************************\");
Console.WriteLine(\"Select a shape type to calculate : \");
int option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Console.WriteLine(\"1\");
CalculateCircle();
break;
case 2:
Console.WriteLine(\"2\");
CalculateSquare();
break;
case 3:
Console.WriteLine(\"3\");
CalculateRectangle();
break;
case 4:
Console.WriteLine(\"4\");
CalculateRhombus();
break;
case 5:
Console.WriteLine(\"5\");
CalculateParallelogram();
break;
case 6:
Console.WriteLine(\"6\");
CalculateTrapezoid();
break;
case 7:
Console.WriteLine(\"7\");
break;
Console.ReadKey();
}
}
private static void CalculateCircle()
{
Console.WriteLine(\"Please enter the radius of the circle\");
double radius = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of Circle is:{0}\", 3.14 * radius * radius);
}
private static void CalculateSquare()
{
Console.WriteLine(\"Enter the side of a square\");
double side = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of Square is:{0}\", side * side);
}
private static void CalculateRectangle()
{
Console.WriteLine(\"Enter the length of the rectangle\");
double l = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the width of the rectangle\");
double w = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of rectangle is :{0}\", l * w);
}
private static void CalculateRhombus()
{
Console.WriteLine(\"Enter thelength of one diagonal of the rhombus\");
double d1 = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter thelength of other diagonal of the rhombus\");
double d2 = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of the Rhombus is : {0}\", (d1 * d2) / 2);
}
private static void CalculateParallelogram()
{
Console.WriteLine(\"Enter the length of the base of the parallelogram\");
double b = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the height of the base of the parallelogram\");
double h = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of the Parallelogram is : {0}\", b * h);
}
private static void CalculateTrapezoid()
{
Console.WriteLine(\"Enter the length of the large base of the trapezoid\");
double lb = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the length of the small base of the trapezoid\");
double sb = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Enter the height of the trapezoid\");
double h = double.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(\"Area of parallelogram is:{0}\", (lb + sb) * (h / 2));
}
}
}




