Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,171 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,579 people online right now. Registration is fast and FREE... Join Now!




Input String Not in correct format error

 
Closed TopicStart new topic

Input String Not in correct format error, Having some trouble overcoming an input string error.

Onker
post 10 Oct, 2008 - 11:49 AM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 43



Thanked 1 times
My Contributions


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.

CODE

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 Oct, 2008 - 12:58 PM
User is online!Profile CardPM

Go to the top of the page

modi123_1
post 10 Oct, 2008 - 12:32 PM
Post #2


D.I.C Addict

Group Icon
Joined: 12 Jun, 2008
Posts: 518



Thanked 10 times

Dream Kudos: 100
My Contributions


Which line was causing the problem?

Side note

cpp
 
if grade3 =="";
break;


should be changed to

cpp
  
if (grade3 =="")
break;
User is online!Profile CardPM

Go to the top of the page

Onker
post 10 Oct, 2008 - 12:48 PM
Post #3


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 43



Thanked 1 times
My Contributions


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 tongue.gif

The line that's giving the problem is this one.
CODE

double hw = Double.Parse(grade3);


I can't believe I forgot to put that in there. *sigh*
User is online!Profile CardPM

Go to the top of the page

PsychoCoder
post 10 Oct, 2008 - 12:52 PM
Post #4


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,921



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


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
User is online!Profile CardPM

Go to the top of the page

Onker
post 10 Oct, 2008 - 12:57 PM
Post #5


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 43



Thanked 1 times
My Contributions


Odd how much of a friend copy past is.
I'm editing the base code to include the line "String grade3 = console.readline();"
User is online!Profile CardPM

Go to the top of the page

Onker
post 10 Oct, 2008 - 02:13 PM
Post #6


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 43



Thanked 1 times
My Contributions


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

CODE

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!
User is online!Profile CardPM

Go to the top of the page

Closed TopicStart new topic
Time is now: 11/21/08 03:09PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month