Advertisement
Guest User

Nested Loops - Lab (05. Travelling)

a guest
Dec 30th, 2020
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 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 Traveling
  8.  
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string destination = Console.ReadLine();
  15.             int neededMoney = int.Parse(Console.ReadLine());
  16.             int sum = 0;
  17.  
  18.             while (destination != "End")
  19.             {
  20.                 int input = int.Parse(Console.ReadLine());
  21.                 sum += input;
  22.                 if (sum >= neededMoney)
  23.                 {
  24.                     Console.WriteLine($"Going to {destination}!");
  25.                     sum = 0;
  26.                     destination = Console.ReadLine();
  27.                     if (destination == "End" || destination == "")
  28.                     {
  29.                         Environment.Exit(0);
  30.                     }
  31.                     neededMoney = int.Parse(Console.ReadLine());
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement