C# – Quick Exchange Rate Calculator – Video
Hello All,
I have created a small video, showing how to make use of the do-while loop for creation of small console applications.
The interesting part of the code is the usage of the do-while loop, which executes the code until something different than “yes” is entered at the end. Pretty useful indeed!
Enjoy the code!
This is the code:
using System;
class Program
{
static void Main()
{
int i = 1;
float exchangeRate, euro, dollar;
Console.WriteLine("Exchange Euro in Dollars");
do
{
Console.Write("Exchange Rate:");
exchangeRate = Convert.ToSingle(Console.ReadLine());
Console.Write("Euro:");
euro = Convert.ToSingle(Console.ReadLine());
dollar= euro*exchangeRate;
Console.WriteLine("You will get " + dollar.ToString("0.00 $"));
Console.Write("Should we end the program? (yes/no)");
string s = Console.ReadLine();
i = string.Compare(s,"yes");
} while (i!=0);
}
}
If you are interested in the way the program functions, you may find it here.
Have a nice day!