Advertisement
skipter

C# Fundamentals - while and if statement / calories calc

Jun 2nd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp9
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var cheese = 500;
  14.             var tomatoSause = 150;
  15.             var salami = 600;
  16.             var pepper = 50;
  17.  
  18.             var totalCalories = 0;
  19.  
  20.             int num = int.Parse(Console.ReadLine());
  21.             string product = null;
  22.             int var = 0;
  23.  
  24.             while (var < num)
  25.             {
  26.                 product = Console.ReadLine().ToLower();
  27.                 var++;
  28.                 if (product == "cheese")
  29.                 {
  30.                     totalCalories += cheese;
  31.                 }
  32.                 if (product == "tomato sauce")
  33.                 {
  34.                     totalCalories += tomatoSause;
  35.                 }
  36.                 if (product == "salami")
  37.                 {
  38.                     totalCalories += salami;
  39.                 }
  40.                 if (product == "pepper")
  41.                 {
  42.                     totalCalories += pepper;
  43.                 }
  44.             }
  45.             Console.WriteLine($"Total calories: {totalCalories}");
  46.  
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement