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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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!