Advertisement
NastySwipy

ConditionalStatementsAndLoops - 08. Calories Counter

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