skipter icon

C# Fundamentals - while and if statement / calories calc

skipter | PRO | 06/02/17 08:38:00 PM UTC | 0 ⭐ | 314 👁️ | Never ⏰ | []
C# |

1.23 KB

|

None

|

0 👍

/

0 👎

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var cheese = 500;
            var tomatoSause = 150;
            var salami = 600;
            var pepper = 50;
 
            var totalCalories = 0;
 
            int num = int.Parse(Console.ReadLine());
            string product = null;
            int var = 0;
 
            while (var < num)
            {
                product = Console.ReadLine().ToLower();
                var++;
                if (product == "cheese")
                {
                    totalCalories += cheese;
                }
                if (product == "tomato sauce")
                {
                    totalCalories += tomatoSause;
                }
                if (product == "salami")
                {
                    totalCalories += salami;
                }
                if (product == "pepper")
                {
                    totalCalories += pepper;
                }
            }
            Console.WriteLine($"Total calories: {totalCalories}");
 
 
        }
    }
}

Comments