Last active
February 5, 2025 17:09
-
-
Save CAHTEXHIK/229ca7091abd348dd37fa42e06fe513e to your computer and use it in GitHub Desktop.
Currency conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace Task13 | |
{ | |
public static class Program12 | |
{ | |
public static void Main() | |
{ | |
const string CommandExit = "Exit"; | |
const string CommandGoldToPlatinum = "1"; | |
const string CommandSilverToPlatinum = "2"; | |
const string CommandSilverToGold = "3"; | |
const string CommandPlatinumToGold = "4"; | |
const string CommandPlatinumToSilver = "5"; | |
const string CommandGoldToSilver = "6"; | |
const string GoldWord = "Золото"; | |
const string SilverWord = "Серебро"; | |
const string PlatinumWord = "Платина"; | |
Random random = new Random(); | |
int minimalValueBalance = 1; | |
int maximumValueBalance = 6; | |
float platinumBalance = random.Next(minimalValueBalance, maximumValueBalance + 1); | |
float platinumToSilverRate = 4.0f; | |
float platinumToGoldRate = 2.0f; | |
float goldBalance = random.Next(minimalValueBalance, maximumValueBalance + 1); | |
float goldToSilverRate = 2.0f; | |
float goldToPlatinumRate = 1.0f; | |
float silverBalance = random.Next(minimalValueBalance, maximumValueBalance + 1); | |
float silverToPlatinumRate = 0.25f; | |
float silverToGoldRate = 0.5f; | |
bool isWorking = true; | |
Console.WriteLine($"{CommandGoldToPlatinum}) {GoldWord} в {PlatinumWord}. Цена конвертации: {goldToPlatinumRate} {GoldWord} за {PlatinumWord}"); | |
Console.WriteLine($"{CommandSilverToPlatinum}) {SilverWord} в {PlatinumWord}. Цена конвертации: {silverToPlatinumRate} {SilverWord} за {PlatinumWord}"); | |
Console.WriteLine($"{CommandSilverToGold}) {SilverWord} в {GoldWord}. Цена конвертации: {silverToGoldRate} {SilverWord} за {GoldWord}"); | |
Console.WriteLine($"{CommandPlatinumToGold}) {PlatinumWord} в {GoldWord}. Цена конвертации: {platinumToGoldRate} {PlatinumWord} за {GoldWord}"); | |
Console.WriteLine($"{CommandPlatinumToSilver}) {PlatinumWord} в {SilverWord}. Цена конвертации: {platinumToSilverRate} {PlatinumWord} за {SilverWord}"); | |
Console.WriteLine($"{CommandGoldToSilver}) {GoldWord} в {SilverWord}. Цена конвертации: {goldToSilverRate} {GoldWord} за {SilverWord}"); | |
Console.WriteLine($"Для выхода введите {CommandExit}"); | |
while (isWorking) | |
{ | |
Console.WriteLine($"На вашем балансе: {platinumBalance} {PlatinumWord} {goldBalance} {GoldWord} {silverBalance} {SilverWord}"); | |
string choice = Console.ReadLine(); | |
switch (choice) | |
{ | |
case CommandGoldToPlatinum: | |
Console.WriteLine($"Сколько {PlatinumWord} вы хотите получить?"); | |
if (float.TryParse(Console.ReadLine(), out float platinumAmount)) | |
{ | |
if (platinumAmount <= 0) | |
{ | |
Console.WriteLine("Количество должно быть больше нуля."); | |
} | |
else | |
{ | |
float requiredGold = platinumAmount / goldToPlatinumRate; | |
if (goldBalance >= requiredGold) | |
{ | |
goldBalance -= requiredGold; | |
platinumBalance += platinumAmount; | |
Console.WriteLine($"Вы обменяли {requiredGold} {GoldWord} на {platinumAmount} {PlatinumWord}."); | |
} | |
else | |
{ | |
Console.WriteLine($"Недостаточно {GoldWord} для обмена. Требуется {requiredGold}, у вас {goldBalance}."); | |
} | |
} | |
} | |
break; | |
case CommandSilverToPlatinum: | |
Console.WriteLine($"Сколько {PlatinumWord} вы хотите получить?"); | |
if (float.TryParse(Console.ReadLine(), out platinumAmount)) | |
{ | |
if (platinumAmount <= 0) | |
{ | |
Console.WriteLine("Количество должно быть больше нуля."); | |
} | |
else | |
{ | |
float requiredSilver = platinumAmount / silverToPlatinumRate; | |
if (silverBalance >= requiredSilver) | |
{ | |
silverBalance -= requiredSilver; | |
platinumBalance += platinumAmount; | |
Console.WriteLine($"Вы обменяли {requiredSilver} {SilverWord} на {platinumAmount} {PlatinumWord}."); | |
} | |
else | |
{ | |
Console.WriteLine($"Недостаточно {SilverWord} для обмена. Требуется {requiredSilver}, у вас {silverBalance}."); | |
} | |
} | |
} | |
break; | |
case CommandSilverToGold: | |
Console.WriteLine($"Сколько {GoldWord} вы хотите получить?"); | |
if (float.TryParse(Console.ReadLine(), out float goldAmount)) | |
{ | |
if (goldAmount <= 0) | |
{ | |
Console.WriteLine("Количество должно быть больше нуля."); | |
} | |
else | |
{ | |
float requiredSilverForGold = goldAmount / silverToGoldRate; | |
if (silverBalance >= requiredSilverForGold) | |
{ | |
silverBalance -= requiredSilverForGold; | |
goldBalance += goldAmount; | |
Console.WriteLine($"Вы обменяли {requiredSilverForGold} {SilverWord} на {goldAmount} {GoldWord}."); | |
} | |
else | |
{ | |
Console.WriteLine($"Недостаточно {SilverWord} для обмена. Требуется {requiredSilverForGold}, у вас {silverBalance}."); | |
} | |
} | |
} | |
break; | |
case CommandPlatinumToGold: | |
Console.WriteLine($"Сколько {GoldWord} вы хотите получить?"); | |
if (float.TryParse(Console.ReadLine(), out goldAmount)) | |
{ | |
if (goldAmount <= 0) | |
{ | |
Console.WriteLine("Количество должно быть больше нуля."); | |
} | |
else | |
{ | |
float requiredPlatinumForGold = goldAmount / platinumToGoldRate; | |
if (platinumBalance >= requiredPlatinumForGold) | |
{ | |
platinumBalance -= requiredPlatinumForGold; | |
goldBalance += goldAmount; | |
Console.WriteLine($"Вы обменяли {requiredPlatinumForGold} {PlatinumWord} на {goldAmount} {GoldWord}."); | |
} | |
else | |
{ | |
Console.WriteLine($"Недостаточно {PlatinumWord} для обмена. Требуется {requiredPlatinumForGold}, у вас {platinumBalance}."); | |
} | |
} | |
} | |
break; | |
case CommandPlatinumToSilver: | |
Console.WriteLine($"Сколько {SilverWord} вы хотите получить?"); | |
if (float.TryParse(Console.ReadLine(), out float silverAmount)) | |
{ | |
if (silverAmount <= 0) | |
{ | |
Console.WriteLine("Количество должно быть больше нуля."); | |
} | |
else | |
{ | |
float requiredPlatinumForSilver = silverAmount / platinumToSilverRate; | |
if (platinumBalance >= requiredPlatinumForSilver) | |
{ | |
platinumBalance -= requiredPlatinumForSilver; | |
silverBalance += silverAmount; | |
Console.WriteLine($"Вы обменяли {requiredPlatinumForSilver} {PlatinumWord} на {silverAmount} {SilverWord}."); | |
} | |
else | |
{ | |
Console.WriteLine($"Недостаточно {PlatinumWord} для обмена. Требуется {requiredPlatinumForSilver}, у вас {platinumBalance}."); | |
} | |
} | |
} | |
break; | |
case CommandGoldToSilver: | |
Console.WriteLine($"Сколько {SilverWord} вы хотите получить?"); | |
if (float.TryParse(Console.ReadLine(), out silverAmount)) | |
{ | |
if (silverAmount <= 0) | |
{ | |
Console.WriteLine("Количество должно быть больше нуля."); | |
} | |
else | |
{ | |
float requiredGoldForSilver = silverAmount / goldToSilverRate; | |
if (goldBalance >= requiredGoldForSilver) | |
{ | |
goldBalance -= requiredGoldForSilver; | |
silverBalance += silverAmount; | |
Console.WriteLine($"Вы обменяли {requiredGoldForSilver} {GoldWord} на {silverAmount} {SilverWord}."); | |
} | |
else | |
{ | |
Console.WriteLine($"Недостаточно {GoldWord} для обмена. Требуется {requiredGoldForSilver}, у вас {goldBalance}."); | |
} | |
} | |
} | |
break; | |
case CommandExit: | |
isWorking = false; | |
break; | |
default: | |
Console.WriteLine("Неверный выбор. Пожалуйста, выберите один из вариантов."); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment