Answer to Question #39611 in C# for vallabh

Question #39611
i want a c# program currency converter.
1
Expert's answer
2014-03-24T10:43:30-0400
using System;

namespace MyPatterns
{
class Singleton
{

private static Singleton Menu;

public static Singleton CreateMenu
{
get
{
if (Menu == null) Menu = new Singleton();
return Menu;
}
}

private Singleton()
{

}

public int ShowMenu(params string[] lines)
{
if (lines.Length < 2) return -1;

int starPos = 0;

for (int i = 0; i < lines.Length; i++)
if (lines[i].Length > starPos) starPos = lines[i].Length;

starPos += 5;

int upLinePos = Console.CursorTop + 1;
int lowLinePos = upLinePos + lines.Length - 1;
int curLine = upLinePos;
Console.WriteLine();

foreach (var line in lines)
{
Console.WriteLine(line);
}

Console.SetCursorPosition(starPos, upLinePos);
Console.Write("*");


ConsoleKeyInfo key;
do
{
key = Console.ReadKey(true);

switch (key.Key)
{
case ConsoleKey.UpArrow:

Console.SetCursorPosition(starPos, curLine);
Console.Write(" ");
if (curLine == upLinePos) curLine = lowLinePos;
else curLine--;
Console.SetCursorPosition(starPos, curLine);
Console.Write("*");
break;

case ConsoleKey.DownArrow:
Console.SetCursorPosition(starPos, curLine);
Console.Write(" ");
if (curLine == lowLinePos) curLine = upLinePos;
else curLine++;
Console.SetCursorPosition(starPos, curLine);
Console.Write("*");
break;

case ConsoleKey.Escape:
Console.SetCursorPosition(0, lowLinePos + 2);
return -1;
}
} while (key.Key != ConsoleKey.Enter);

Console.SetCursorPosition(0, lowLinePos + 2);
return curLine - upLinePos;
}

}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Currency_Converter
{
class Program
{
enum Currences { USD, Euro, Australian_Dollar, Pound_Sterling, Canadian_Dollar, Russian_Rubl };
static void Main(string[] args)
{

double[] curr = { 1, 0.73, 1.1155, 0.599, 1.10766, 31.88 }; //usd, cdol , austr, ster ,
double amount = 0;



amount = 5;
Console.Clear();
Console.WriteLine("Choose your currency(ESC -EXIT)");

int start = MyPatterns.Singleton.CreateMenu.ShowMenu("USD", "Euro", "Australian Dollar", "Pound Sterling", "Canadian Dollar", "Russian Rubl");
if (start < 0)
{
Environment.Exit(0);
}

Console.WriteLine("Enter your amount:");

if (!Double.TryParse(Console.ReadLine().Replace('.', ','), out amount)||amount<=0)
{
Console.WriteLine("Wrong input. Press any key to exit...");
Console.Read();
return;
}
Console.WriteLine("Convert into:");
int num= MyPatterns.Singleton.CreateMenu.ShowMenu("USD", "Euro", "Australian Dollar", "Pound Sterling", "Canadian Dollar", "Russian Rubl");
if (num == -1) return;


Console.WriteLine("You will get {0,15:###,###.##} {1}", amount/curr[start]*curr[num],((Currences)num).ToString());
Console.WriteLine("Press any key to continue...");
Console.Read();


}
}
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS