kirililchev3

CaloriesCounter - switch case

May 20th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P08CaloriesCounter
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int calories = 0;
  11.  
  12.             for (int i = 0; i < n; i++)
  13.             {
  14.                 string ingredient = Console.ReadLine().ToLower();
  15.  
  16.               switch (ingredient)
  17.                 {
  18.                     case "cheese":
  19.                         calories += 500;
  20.                         break;
  21.                     case "tomato sauce":
  22.                         calories += 150;
  23.                         break;
  24.                     case "salami":
  25.                         calories += 600;
  26.                         break;
  27.                     case "pepper":
  28.                         calories += 50;
  29.                         break;
  30.                     default:
  31.                         calories += 0;
  32.                         break;
  33.                 }
  34.             }
  35.             Console.WriteLine($"Total calories: {calories}");
  36.            
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment