Cinema - задачката, ако някой може да ми каже къде ми е грешката?
Това е моето решение:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cinema
{
class Program
{
static void Main(string[] args)
{
var TypeOfMovie = Console.ReadLine();
var lines = int.Parse(Console.ReadLine());
var columns = int.Parse(Console.ReadLine());
var price = 0.0;
if (TypeOfMovie == "Premiere")
{ price = 12.00;
}
else if (TypeOfMovie == "Normal")
{ price = 7.50;
}
else if (TypeOfMovie == " Discount")
{ price = 5.00;
}
Console.WriteLine("{0,F2}", lines * columns * price);
}
}
}
Намерих на един колега решението със " switch , case" начина:
| namespace Cinema | |
| { | |
| using System; | |
| class Cinema | |
| { | |
| static void Main() | |
| { | |
| var movie = Console.ReadLine().ToLower(); | |
| var rows = int.Parse(Console.ReadLine()); | |
| var columns = int.Parse(Console.ReadLine()); | |
| double price = 0.0; | |
| switch (movie) | |
| { | |
| case "premiere": price = 12.0; break; | |
| case "normal": price = 7.5; break; | |
| case "discount": price = 5.0; break; | |
| default: | |
| break; | |
| } | |
| Console.WriteLine("{0:f2}", rows * columns * price); | |
| } | |
| } | |
| } |
Някакви идеи защо "switch,case" варянта работи, а "if-else" начина не се компилира?