Advertisement
EmoRz

C# BASIC SYNTAX - EXERCISES

May 16th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Excercises
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Character Stats
  10.             var name = Console.ReadLine();
  11.             var currentHealth = int.Parse(Console.ReadLine());
  12.             var maxHealth = int.Parse(Console.ReadLine());
  13.             var currentEnergy = int.Parse(Console.ReadLine());
  14.             var maxEnergy = int.Parse(Console.ReadLine());
  15.             //
  16.             Console.WriteLine($"Name: {name}");
  17.             Console.WriteLine($"Health: |{new string('|', currentHealth)}{new string('.', maxHealth-currentHealth)}|");
  18.             Console.WriteLine($"Energy: |{new string('|', currentEnergy)}{new string('.', maxEnergy-currentEnergy)}|");
  19.  
  20.         }
  21.  
  22.         private static void Label()
  23.         {
  24.             var name = Console.ReadLine();
  25.             double volume = double.Parse(Console.ReadLine());
  26.             double energy = double.Parse(Console.ReadLine());
  27.             double sugar = double.Parse(Console.ReadLine());
  28.             //
  29.             var label1 = $"{volume}ml {name}:";
  30.             Console.WriteLine(label1);
  31.             var energyContent = energy * (volume / 100);
  32.             var sugarContent = sugar * (volume / 100);
  33.             var label2 = $"{energyContent}kcal, {sugarContent}g sugars";
  34.             Console.WriteLine(label2);
  35.         }
  36.  
  37.         private static void Mile_Km()
  38.         {
  39.             //1 mile == 1.60934 kilometers
  40.             var mile = double.Parse(Console.ReadLine());
  41.             var inKm = mile * 1.60934;
  42.             Console.WriteLine($"{inKm:f2}");
  43.         }
  44.  
  45.         private static void Rectangle_Area()
  46.         {
  47.             var a = double.Parse(Console.ReadLine());
  48.             var b = double.Parse(Console.ReadLine());
  49.             var area = a * b;
  50.             Console.WriteLine($"{area:f2}");
  51.         }
  52.  
  53.         private static void Debit_Card_Number()
  54.         {
  55.             var n1 = int.Parse(Console.ReadLine());
  56.             var n2 = int.Parse(Console.ReadLine());
  57.             var n3 = int.Parse(Console.ReadLine());
  58.             var n4 = int.Parse(Console.ReadLine());
  59.             //
  60.             Console.WriteLine($"{n1:d4} {n2:d4} {n3:d4} {n4:d4}");
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement