1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I am getting error like this "System.FormatException was unhandled " Help me

Discussion in 'C#' started by rocky swagger, Sep 9, 2010.

  1. rocky swagger

    rocky swagger New Member

    Joined:
    Sep 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hello friends

    I can not convert string to double , I am new to C sharp . Please help me out
    I tryed parse,covert, everything . I have pasted the code below .
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class sales
        {
            double commrate = 0.01;
            String andrea;
            String emily;
            String tom;
            double andreaAmount;
            double emilyAmount;
            double tomAmount;
            double amount;
    	void getSalesName()
    	{
            Console.WriteLine("Enter the sale person name intial and If u want to exit press f");
    		String s = Console.ReadLine();
    	     
    	     if(s.Equals("A")|| s.Equals("B")|| s.Equals("T"))
    	     {
    	    	 Console.WriteLine("Enter the amount of sales");
                 Console.ReadLine();
                 string s1 = Console.ReadLine();
                   // Error in the below line 
    	    	  amount = double.Parse(s1);
                             
    			 if(s.Equals("A"))
    	    	 {
    	    		 andreaAmount = andreaAmount + amount *commrate ; 
    	     	 }
    	    	 else if(s.Equals("B"))
    	    	 {
    	    		 emilyAmount = emilyAmount + amount *commrate;
                         	 }
    	    	 else
    	    	 {
    	    		tomAmount = tomAmount + amount * commrate ; 
    	    	 }
    	    	 
    			 getSalesName();
    	     }
    	     else if(!s.Equals("F"))
    	     {
    	    	 Console.WriteLine("please reEnter the corrent Intial of the salesPersonName");
                 Console.Read();
    	    	 getSalesName();
    	     }
    	     else if(s.Equals("F")) 
    	     {
    	    	 
    	    	 Console.WriteLine("The total sales person sales are");
    	    	 Console.Write("Andrea " + andreaAmount);
    	    	 Console.Write("Emily " + emilyAmount);
                 Console.Write("Tom " + tomAmount);
                 Console.ReadLine();  		   
    	     }
    		
    	}
    
            static void Main(string[] args)
            {
                sales sa = new sales();
                sa.getSalesName();
            }
        }
    }
     

Share This Page