Класс "банковский счет". Проблема в выводе типа валюты в консоль - C#
Формулировка задачи:
Проблема в выводе типа валюты в консоль.
Как вывести usd, eur, rub в консоль?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bankbillclass
{
public class bankbillclass
{
// поля класса
private int id;
private double bill;
public enum currency {usd, eur, rub};
private currency curr1 = new currency();
private bool isOpened = false;
// конструктор
public bankbillclass()
{
Console.WriteLine("Банковский счет не определен!");
bill = 0;
curr1 = (currency)0;
}
// деструктор
~bankbillclass()
{
// магия деструктора
}
// функция открытия аккаунта
public void OpenAccount()
{
if (isOpened == true)
{
Console.WriteLine("Счет уже открыт!");
}
else
{
Console.Write("Введите номер счета: ");
id = Convert.ToInt32(Console.ReadLine());
while (id <= 0)
{
Console.WriteLine("Неверный ввод!");
Console.Write("Введите номер счета: ");
id = Convert.ToInt32(Console.ReadLine());
}
Console.Write("Хранимая валюта (0 - usd, 1 - eur, 2 - rub): ");
int tmp = Convert.ToInt32(Console.ReadLine());
while (tmp < 0 && tmp > 2)
{
Console.WriteLine("Неверный ввод!");
Console.Write("Хранимая валюта (0 - usd, 1 - eur, 2 - rub): ");
tmp = Convert.ToInt32(Console.ReadLine());
}
curr1 = (currency)(tmp);
isOpened = true;
Console.WriteLine("Счет открыт!");
}
}
// функция вклада
public void Deposit()
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
Console.Write("Величина депозита: ");
double tmp = Convert.ToDouble(Console.ReadLine());
while (tmp <= 0)
{
Console.WriteLine("Неверный ввод!");
Console.Write("Величина депозита: ");
tmp = Convert.ToDouble(Console.ReadLine());
}
bill += tmp;
}
}
public void Deposit(double tmp)
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
bill += tmp;
}
}
// функция снятия со счета
public void Withdraw()
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
Console.Write("Списание со счета: ");
double tmp = Convert.ToDouble(Console.ReadLine());
while (tmp <= 0)
{
Console.WriteLine("Неверный ввод!");
Console.Write("Списание со счета: ");
tmp = Convert.ToDouble(Console.ReadLine());
}
bill -= tmp;
}
}
public void Withdraw(double tmp)
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
bill -= tmp;
}
}
// функция перевода в доллары
public double ConvertToDefault(double n, currency curr)
{
if (curr == (currency)0)
{
return n;
}
else if (curr == (currency)1)
{
return n * 1.36;
}
else
{
return n * 0.03;
}
}
// перевод долларов в соотв. валюту
public double ConvertTo(double n, currency curr)
{
if (curr == (currency)0)
{
return n;
}
else if (curr == (currency)1)
{
return n / 1.36;
}
else
{
return n / 0.03;
}
}
// получения типа хранимой валюты
public currency GetCurrency()
{
return this.curr1;
}
// статус счета
public void Status()
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
Console.WriteLine("Номер счета: {0}", id);
//Console.WriteLine("Денежные средства: {0} {2}", bill, curr1);
Console.WriteLine("Денежные средства: {0}", bill);
}
}
// перевод с одного счета на другой
public void Transfer(bankbillclass bank1)
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
Console.Write("Сумма перевода: ");
double tmp = Convert.ToDouble(Console.ReadLine());
while (tmp <= 0)
{
Console.WriteLine("Неверный ввод!");
Console.Write("Сумма перевода: ");
tmp = Convert.ToDouble(Console.ReadLine());
}
this.Withdraw(tmp);
tmp = ConvertToDefault(tmp, this.GetCurrency());
tmp = ConvertTo(tmp, bank1.GetCurrency());
bank1.Deposit(tmp);
}
}
}
} public void Status()
{
if (isOpened == false)
{
Console.WriteLine("Счет закрыт!");
}
else
{
Console.WriteLine("Номер счета: {0}", id);
//Console.WriteLine("Денежные средства: {0} {2}", bill, curr1); <--- в этой строке проблема
Console.WriteLine("Денежные средства: {0}", bill);
}
}Решение задачи: «Класс "банковский счет". Проблема в выводе типа валюты в консоль»
textual
Листинг программы
Console.WriteLine("Денежные средства: {0} {1}", bill, curr1);