Architect Arithmetic Bonus Challenge

Hello,

I was working on the Architect Arithmetic challenge.
I did pretty okay, but then when I got to the bonus challenge, it seems to not work.
I am attempting to use a Console.ReadLine() statement trigger different results for a Method. However, most of the errors I get are about the variables I am attempting to use in the switch statement.

Might this be an issue with the scope?

using System;

namespace ArchitectArithmetic
{
  class Program
  {
	
	public static void CalculateTotalCost(string placeName)
	{
		string buildingName;
		
		
		switch(buildingName)
		{

        
			case "TAJ MAHAL":
			double length = 90.5;
			double width = 90.5;
			double bottom = 24;
			double height = 24;
			double rectArea = (length * width);
			double triArea = (.05 * bottom * height);
			double totalArea = (rectArea * triArea);
			double totalCost = Math.Round( totalArea * 180);
			Console.WriteLine($"The plan for the Taj Mahal would could {totalCost} pesos!");
			break;
			
			case "MOSQUE":
			double length1 = 284;
			double width1 = 264;
			double length2 = 106;
			double width2 = 180;
			double bottom = 264;
			double height = 84;
			double rectArea1 = (length1 * width1);
			double rectArea2 = (length2 * width2);
			double triArea = (0.5 * bottom * height);
			double totalArea = (rectArea1 + rectArea2 + triArea);
			double totalCost = Math.Round( totalArea * 180);
			Console.WriteLine($"The total cost of constructing the Grand Mosque in the modern era is {totalCost} pesos");
			break;
			
			break;
			
			case "TEOTIHUACAN":
			
			double length = 2500;
			double width = 1500;
			double bottom = 750;
			double height = 500;
			double radius;
			double cirArea = Math.PI * Math.Pow(radius, 2);
			double rectArea = (length * width);
			double triArea = (.05 * bottom * height);
			double totalArea = (rectArea + * triArea + cirArea);
			double totalCost = Math.Round( totalArea * 180);
			Console.WriteLine($"The total cost of constructing Teotihuacan in the modern era is {totalCost} pesos");
			break;
			
			
		}
		
	}
    
    public static void Main(string[] args)
    {
    
	  
	  string placeName;
	  Console.WriteLine("Welcome to this thinga-ma-jig! \n Type in the name of one of three of these words to get a cost \n \'TEOTIHUACAN', \'MOSQUE', \'TAJ MAHAL' ");
	  placeName = Console.ReadLine();
	  placeName.ToUpper();
	  CalculateTotalCost(placeName);
      
     
      
      
      
    }
  }
} 
2 Likes

You can add another scope by nesting code inside {}
(or move them out into separate functions)

2 Likes

I’m sorry, I don’t quite understand. How may that help me with correctly executing this function?

Wasn’t the problem that you’re declaring the same variable more than once in the same scope?
The solution then would be to either use different names, or put them in different scopes.

2 Likes

Sorry for my late replay and thank you very much for your help! This helped me alot. The final version of the code came out like:

using System;
 
namespace ArchitectArithmetic
{
  class Program
  {
      public double length;
        public double width;
        public double bottom;
        public double height;
        public double rectArea;
        public double rectArea1;
        public double rectArea2;
        public double triArea;
        public double totalArea;
        public double totalCost;
   
    public static void CalculateTotalCost(string placeName)
    {

       
       // PLEASE REMEMBER! You must use brackets to separate the scopes for this to work
        switch(placeName)
        {
 
       
            case "TAJ MAHAL":
			{
            double length = 90.5;
            double width = 90.5;
            double bottom = 24;
            double height = 24;
            double rectArea = (length * width);
            double triArea = (.05 * bottom * height);
            double totalArea = (rectArea * triArea);
            double totalCost = Math.Round( totalArea * 180);
            Console.WriteLine($"The plan for the Taj Mahal would could {totalCost} pesos!");
            break;
			}
            
			case "MOSQUE":
			{
            double length1 = 284;
            double width1 = 264;
            double length2 = 106;
            double width2 = 180;
            double bottom = 264;
            double height = 84;
            double rectArea1 = (length1 * width1);
            double rectArea2 = (length2 * width2);
            double triArea = (0.5 * bottom * height);
            double totalArea = (rectArea1 + rectArea2 + triArea);
            double totalCost = Math.Round( totalArea * 180);
            Console.WriteLine($"The total cost of constructing the Grand Mosque in the modern era is {totalCost} pesos");
            break;
			}
			
            case "TEOTIHUACAN":
           
		   {
            double length = 2500;
            double width = 1500;
            double bottom = 750;
            double height = 500;
            double radius = 375;
            double cirArea = Math.PI * Math.Pow(radius, 2);
            double rectArea = (length * width);
            double triArea = (.05 * bottom * height);
            double totalArea = (rectArea + triArea + cirArea);
            double totalCost = Math.Round( totalArea * 180);
            Console.WriteLine($"The total cost of constructing Teotihuacan in the modern era is {totalCost} pesos");
            break;
           }
           
        }
       
    }
   
    public static void Main(string[] args)
    {
   
     
      string placeName;
      Console.WriteLine("Welcome to this thinga-ma-jig! \n Type in the name of one of three of these words to get a cost \n \'TEOTIHUACAN', \'MOSQUE', \'TAJ MAHAL' ");
      placeName = Console.ReadLine();
      placeName = placeName.ToUpper(); // Remember to redefine it and THEN place the .ToUpper() function on it
      CalculateTotalCost(placeName);
          
    }
  }
}
1 Like

I have a question about your code!

If I’m not mistaken, In the bonus task you had to subtract the triangles in the Taj Mahal and also for the Mosque as well, because if you see in the projects the triangles are missing in the Taj Mahal project as well as in the Mosque Project!