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