none
cannot implicitly convert type string to double RRS feed

  • Question

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

    namespace Currency
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Declare Source and Target Currency.
                string SCurrency, TCurrency;

                //Declare and intialising a String currency array and a Double rate array.
                String[] currency = new String[] {"Euro","Rupees","Dirhams"};
                double[] rateAR =new double[] {0.73,62.68,3.67};
                double TAmount,SAmount,Rate;

                //Printing the TITLE and setting font color.
                Console.Title = "Currency Application";
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("********CURRENCY CONVERTOR*********");

                //Getting the Source and Target Currency.
                Console.WriteLine("Enter the source currency in Dollars: ");
                SCurrency = System.Console.ReadLine();
                Console.WriteLine("Enter the target currency : ");
                TCurrency = System.Console.ReadLine();
                Console.WriteLine("Enter the amount to convert : ");
                SAmount = System.Console.ReadLine(); ------------ > ERROR
                for(int i=0;i<3;i++)
                {
                    if (TCurrency == currency[i])
                    {
                        rateAR[i]=Rate;
                    }
                }

                TAmount = SAmount * Rate;
                String StringAmount = Convert.ToString(TAmount);
                System.Console.WriteLine("Converted Amount : " + StringAmount + ".");

                Console.BackgroundColor = ConsoleColor.Black;


                Console.ReadLine();
    Saturday, January 25, 2014 6:22 PM

Answers

  • You can change it to something like this,

            static void Main(string[] args)
            {
               // Declare Source and Target Currency.
                string SCurrency, TCurrency;
                //Declare and intialising a String currency array and a Double rate array.
                String[] currency = new String[] {"Euro","Rupees","Dirhams"};
                double[] rateAR =new double[] {0.73,62.68,3.67};
                double TAmount,SAmount,Rate = 0;
                //Printing the TITLE and setting font color.
                Console.Title = "Currency Application";
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("********CURRENCY CONVERTOR*********");
                //Getting the Source and Target Currency.
                Console.WriteLine("Enter the source currency in Dollars: ");
                SCurrency = System.Console.ReadLine();
                Console.WriteLine("Enter the target currency : ");
                TCurrency = System.Console.ReadLine();
                Console.WriteLine("Enter the amount to convert : ");
                string amount = System.Console.ReadLine();
                while (!Double.TryParse(amount, out SAmount))
                {
                    Console.WriteLine("ERROR: invalid amount");
                    Console.WriteLine("Enter the amount to convert : ");
                    amount = System.Console.ReadLine();
                }
                for(int i=0;i<3;i++)
                {
                    if (TCurrency == currency[i])
                    {
                        Rate = rateAR[i];
                    }
                }
                TAmount = SAmount * Rate;
                String StringAmount = Convert.ToString(TAmount);
                System.Console.WriteLine("Converted Amount : " + StringAmount + ".");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ReadLine();
            }


    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    Saturday, January 25, 2014 6:39 PM