Input String Not in correct format error

Having some trouble overcoming an input string error.

Page 1 of 1

5 Replies - 2475 Views - Last Post: 10 October 2008 - 03:13 PM Rate Topic: -----

#1 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Input String Not in correct format error

Post icon  Posted 10 October 2008 - 12:49 PM

I've been working on this same project for a while, and come across a completely different issue from what I was having previously. (Which I got worked out thanks to some help from you guys*Jeff*)

here's the code chunk in question.

while (another)
{
	double temp = 0;
	int count = 0;
	Console.Write("Homework: ");
		string grade3 = Console.ReadLine();
	double hw = Double.Parse(grade3);
	temp = hw + temp;
	hwGrade = ((temp / count) * .2);

	if grade3 =="";
		break;



I'm getting an error of "Input string was not in a correct format"

I'm not understanding why I'm getting the error here, when the same or similar set up elsewhere in the program works perfectly fine.

Anyone have an answer to this one?

This post has been edited by Onker: 10 October 2008 - 01:58 PM


Is This A Good Question/Topic? 1

Replies To: Input String Not in correct format error

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8909
  • View blog
  • Posts: 33,398
  • Joined: 12-June 08

Re: Input String Not in correct format error

Posted 10 October 2008 - 01:32 PM

Which line was causing the problem?

Side note

 
 if grade3 =="";
break;


should be changed to

  
if (grade3 =="")
break;


Was This Post Helpful? 0
  • +
  • -

#3 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: Input String Not in correct format error

Posted 10 October 2008 - 01:48 PM

Sorry, that was a typo, the code's on my laptop and I had to transfer it in here by hand, no wireless at work :P

The line that's giving the problem is this one.
double hw = Double.Parse(grade3);



I can't believe I forgot to put that in there. *sigh*
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Input String Not in correct format error

Posted 10 October 2008 - 01:52 PM

If grade3 is anything other than a numeric value then you'll get that error. Do a Console.WriteLine before that line to see what it's value is
Was This Post Helpful? 0
  • +
  • -

#5 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: Input String Not in correct format error

Posted 10 October 2008 - 01:57 PM

Odd how much of a friend copy past is.
I'm editing the base code to include the line "String grade3 = console.readline();"
Was This Post Helpful? 0
  • +
  • -

#6 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: Input String Not in correct format error

Posted 10 October 2008 - 03:13 PM

Solved it, it was an issue with the order of the statements.

while(another)
				{
					Console.Write("Homework: ");
					string grade3 = Console.ReadLine();
					if (grade3 == "")
					{
						break;
					}
					double hw = Convert.ToDouble(grade3);
					temp = hw + temp;
					hwGrade = ((temp / count) * .2);
					
				}



is the functional version. Now I've got one last bug to chase down and I'm done!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1