Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 18, 2025 11:18
Show Gist options
  • Select an option

  • Save Strelok78/37f3e625411307e2a67ce64e2d9306ab to your computer and use it in GitHub Desktop.

Select an option

Save Strelok78/37f3e625411307e2a67ce64e2d9306ab to your computer and use it in GitHub Desktop.
Currency convertor
using System.Diagnostics;
namespace iJuniorPractice;
class Program
{
static void Main(string[] args)
{
const int CommandexchangeRateRubToUsd = 1;
const int CommandexchangeRateRubToEuro = 2;
const int CommandexchangeRateUsdToRub = 3;
const int CommandexchangeRateEuroToRub = 4;
const int CommandexchangeRateEuroToUsd = 5;
const int CommandexchangeRateUsdToEuro = 6;
const int CommandExit = 7;
string[] menuTextArray =
{
"Main Menu:",
$"{CommandexchangeRateRubToUsd} - Convert Rub to Usd.",
$"{CommandexchangeRateRubToEuro} - Convert Rub to Euro.",
$"{CommandexchangeRateUsdToRub} - Convert Usd to Rub.",
$"{CommandexchangeRateEuroToRub} - Convert Euro to Rub.",
$"{CommandexchangeRateEuroToUsd} - Convert Euro to Usd.",
$"{CommandexchangeRateUsdToEuro} - Convert Usd to Euro.",
$"{CommandExit} - Exit."
};
string enterCommandRequestText = "Enter your command: ";
string enterValueRequstText = "Enter value to convert (use \",\" to enter non-integral): ";
string errorCommandText = "Error, incorrect command";
string errorValueEntered = "Error, enter digit.";
string errorMaxValue = "Error, entered value is too big, try again...";
string continueMessage = "Press any key to continue...";
string exitMessage = "Goodbye...";
float balanceRub = 100;
float balanceEuro = 100;
float balanceUsd = 100;
float exchangeRateRubToUsd = 0.01219f;
float exchangeRateUsdToRub = 82.03f;
float exchangeRateRubToEuro = 0.01073f;
float exchangeRateEuroToRub = 93.19f;
float exchangeRateUsdToEuro = 0.88487f;
float exchangeRateEuroToUsd = 1.1301f;
bool isConvert = true;
int enteredCommand;
float enteredConvertValue;
while (isConvert)
{
Console.Clear();
for (int i = 0; i < menuTextArray.Length; i++)
{
Console.WriteLine(menuTextArray[i]);
}
Console.WriteLine($"balance: Usd - {balanceUsd}, Euro - {balanceEuro}, Rub - {balanceRub}");
Console.WriteLine(enterCommandRequestText);
while (int.TryParse(Console.ReadLine(), out enteredCommand) == false)
{
Console.WriteLine(errorValueEntered);
}
switch (enteredCommand)
{
case CommandexchangeRateRubToUsd:
Console.WriteLine(enterValueRequstText);
while (float.TryParse(Console.ReadLine(), out enteredConvertValue) == false)
{
Console.WriteLine(errorValueEntered);
}
if (balanceRub - enteredConvertValue >= 0)
{
balanceRub -= enteredConvertValue;
balanceUsd += enteredConvertValue * exchangeRateRubToUsd;
}
else
{
Console.WriteLine(errorMaxValue);
}
break;
case CommandexchangeRateRubToEuro:
Console.WriteLine(enterValueRequstText);
while (float.TryParse(Console.ReadLine(), out enteredConvertValue) == false)
{
Console.WriteLine(errorValueEntered);
}
if (balanceRub >= enteredConvertValue)
{
balanceRub -= enteredConvertValue;
balanceEuro += enteredConvertValue * exchangeRateRubToEuro;
}
else
{
Console.WriteLine(errorMaxValue);
}
break;
case CommandexchangeRateUsdToRub:
Console.WriteLine(enterValueRequstText);
while (float.TryParse(Console.ReadLine(), out enteredConvertValue) == false)
{
Console.WriteLine(errorValueEntered);
}
if (balanceUsd >= enteredConvertValue)
{
balanceUsd -= enteredConvertValue;
balanceRub += enteredConvertValue * exchangeRateUsdToRub;
}
else
{
Console.WriteLine(errorMaxValue);
}
break;
case CommandexchangeRateEuroToRub:
Console.WriteLine(enterValueRequstText);
while (float.TryParse(Console.ReadLine(), out enteredConvertValue) == false)
{
Console.WriteLine(errorValueEntered);
}
if (balanceEuro >= enteredConvertValue)
{
balanceEuro -= enteredConvertValue;
balanceRub += enteredConvertValue * exchangeRateEuroToRub;
}
else
{
Console.WriteLine(errorMaxValue);
}
break;
case CommandexchangeRateEuroToUsd:
Console.WriteLine(enterValueRequstText);
while (float.TryParse(Console.ReadLine(), out enteredConvertValue) == false)
{
Console.WriteLine(errorValueEntered);
}
if (balanceEuro >= enteredConvertValue)
{
balanceEuro -= enteredConvertValue;
balanceUsd += enteredConvertValue * exchangeRateEuroToUsd;
}
else
{
Console.WriteLine(errorMaxValue);
}
break;
case CommandexchangeRateUsdToEuro:
Console.WriteLine(enterValueRequstText);
while (float.TryParse(Console.ReadLine(), out enteredConvertValue) == false)
{
Console.WriteLine(errorValueEntered);
}
if (balanceUsd >= enteredConvertValue)
{
balanceUsd -= enteredConvertValue;
balanceEuro += enteredConvertValue * exchangeRateUsdToEuro;
}
else
{
Console.WriteLine(errorMaxValue);
}
break;
case CommandExit:
isConvert = false;
Console.WriteLine(exitMessage);
break;
default:
Console.WriteLine(errorCommandText);
break;
}
Console.WriteLine(continueMessage);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment