3 Replies - 483 Views - Last Post: 14 July 2010 - 02:40 AM Rate Topic: -----

#1 Guest_daniel*


Reputation:

error with a simple readline statement

Posted 14 July 2010 - 02:04 AM

can you guys please tell me what am i doing wrong? this is driving me crazy....


Console.Write("Please enter your age here: ");
string myAge = Console.ReadLine();
int myAgenum = Convert.ToInt32(myAge);

Console.WriteLine("You are {0) years old!", myAgenum);



------
i execute the program, and after trying to enter a number and i get this error window that asks me if i want to send an error report...
what am i missing? why wont it convert the myAge string to an int?

thanks!

Is This A Good Question/Topic? 0

Replies To: error with a simple readline statement

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: error with a simple readline statement

Posted 14 July 2010 - 02:12 AM

Compare these to lines very closely and you'll see that you're using a wrong closing bracelet for your input argument:

Console.WriteLine("You are {0} years old!", myAgenum);
Console.WriteLine("You are {0) years old!", myAgenum);


Was This Post Helpful? 0
  • +
  • -

#3 Guest_daniel*


Reputation:

Re: error with a simple readline statement

Posted 14 July 2010 - 02:17 AM

View PostFlashM, on 14 July 2010 - 01:12 AM, said:

Compare these to lines very closely and you'll see that you're using a wrong closing bracelet for your input argument:

Console.WriteLine("You are {0} years old!", myAgenum);
Console.WriteLine("You are {0) years old!", myAgenum);


oh boy what a stupid mistake

works fine now, thanks for your help :]

by the way, why did the compiler let me run the code? isnt that like a syntax error? i mean, he's supposed to treat {0} as calling for a variable right?
was he thinking that {0) was something that i want him to write on the screen?
Was This Post Helpful? 0

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: error with a simple readline statement

Posted 14 July 2010 - 02:40 AM

exactly... It was a perfectly valid code until it hit the runtime..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1