Last active
May 16, 2023 15:59
-
-
Save Strelok78/ba8b903c9b808a962f41694ff86ac02c to your computer and use it in GitHub Desktop.
The user has a balance in each of the presented currencies. He may ask to convert part of the balance from one currency to another. (3 currencies in total)
This file contains hidden or 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
namespace MyCode | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string CommandExit = "0"; | |
const string CommandUSDtoRUB = "1"; | |
const string CommandUSDtoEUR = "2"; | |
const string CommandRUBtoUSD = "3"; | |
const string CommandRUBtoEUR = "4"; | |
const string CommandEURtoUSD = "5"; | |
const string CommandEURtoRUB = "6"; | |
float balanceUSD; | |
float balanceRUB; | |
float balanceEUR; | |
float rubToUSD = 0.0143f; | |
float rubToEUR = 0.0133f; | |
float usdToEUR = 0.9321f; | |
float exchanger; | |
string enteredCode; | |
bool isActive = true; | |
Console.WriteLine("Enter your USD balance: "); | |
balanceUSD = float.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter your RUB balance: "); | |
balanceRUB = float.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter your EUR balance: "); | |
balanceEUR = float.Parse(Console.ReadLine()); | |
while (isActive) | |
{ | |
Console.WriteLine($"\nYour balances are: {balanceUSD} USD, {balanceRUB} RUB, {balanceEUR} EUR"); | |
Console.WriteLine("Enter number according your need: \n" + | |
$"{CommandUSDtoRUB} - USD to RUB\n" + | |
$"{CommandUSDtoEUR} - USD to EUR\n" + | |
$"{CommandRUBtoUSD} - RUB to USD\n" + | |
$"{CommandRUBtoEUR} - RUB to EUR\n" + | |
$"{CommandEURtoUSD} - EUR to USD\n" + | |
$"{CommandEURtoRUB} - EUR to RUB\n" + | |
$"{CommandExit} - exit\n"); | |
enteredCode = Console.ReadLine(); | |
switch (enteredCode) | |
{ | |
case CommandExit: | |
Console.WriteLine("Exit"); | |
isActive = false; | |
break; | |
case CommandUSDtoRUB: | |
Console.WriteLine("Enter amount to exchange:"); | |
exchanger = float.Parse(Console.ReadLine()); | |
if (exchanger <= balanceUSD) | |
{ | |
balanceRUB += exchanger / rubToUSD; | |
balanceUSD -= exchanger; | |
} | |
Console.WriteLine("Error, you do not have required amount of money!\n"); | |
break; | |
case CommandUSDtoEUR: | |
Console.WriteLine("Enter amount to exchange:"); | |
exchanger = float.Parse(Console.ReadLine()); | |
if (exchanger <= balanceUSD) | |
{ | |
balanceEUR += exchanger * usdToEUR; | |
balanceUSD -= exchanger; | |
} | |
Console.WriteLine("Error, you do not have required amount of money!\n"); | |
break; | |
case CommandRUBtoUSD: | |
Console.WriteLine("Enter amount to exchange:"); | |
exchanger = float.Parse(Console.ReadLine()); | |
if (exchanger <= balanceRUB) | |
{ | |
balanceUSD += exchanger * rubToUSD; | |
balanceRUB -= exchanger; | |
break; | |
} | |
Console.WriteLine("Error, you do not have required amount of money!\n"); | |
break; | |
case CommandRUBtoEUR: | |
Console.WriteLine("Enter amount to exchange:"); | |
exchanger = float.Parse(Console.ReadLine()); | |
if (exchanger <= balanceRUB) | |
{ | |
balanceEUR += exchanger * rubToEUR; | |
balanceRUB -= exchanger; | |
break; | |
} | |
Console.WriteLine("Error, you do not have required amount of money!\n"); | |
break; | |
case CommandEURtoUSD: | |
Console.WriteLine("Enter amount to exchange:"); | |
exchanger = float.Parse(Console.ReadLine()); | |
if (exchanger <= balanceEUR) | |
{ | |
balanceUSD += exchanger / usdToEUR; | |
balanceEUR -= exchanger; | |
break; | |
} | |
Console.WriteLine("Error, you do not have required amount of money!\n"); | |
break; | |
case CommandEURtoRUB: | |
Console.WriteLine("Enter amount to exchange:"); | |
exchanger = float.Parse(Console.ReadLine()); | |
if (exchanger <= balanceEUR) | |
{ | |
balanceRUB += exchanger / rubToEUR; | |
balanceEUR -= exchanger; | |
break; | |
} | |
Console.WriteLine("Error, you do not have required amount of money!\n"); | |
break; | |
default: | |
Console.WriteLine("Error"); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment