CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    2

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

    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 .


    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();
    }
    }
    }

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

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

    And why do you have two Console.ReadLine() calls after your prompt? Your second ReadLine() is probably just returning an empty string, i.e., you enter a number, hit enter (first ReadLine(), which is discarded), and then hit enter again.

  3. #3
    Join Date
    Sep 2010
    Posts
    2

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

    got it , when i deleted the first console.readline() , I got it complied . Thank u very much my friend.


    rocky

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured