Click here to Skip to main content
15,924,507 members
Home / Discussions / C#
   

C#

 
Questionhelp me in this code Pin
Kulbeer sidhu2-Apr-16 2:18
Kulbeer sidhu2-Apr-16 2:18 
AnswerRe: help me in this code Pin
OriginalGriff2-Apr-16 2:31
mveOriginalGriff2-Apr-16 2:31 
First off, don't use int.Parse - use int.TryParse instead:
C#
int a;
if (!int.TryParse(Console.ReadLine(), out a))
   {
   // Report problem to the user - he typed wrong!
   ...
   }
else
   {
   // The value is fine.
   ...
   }
That way your code won't crash if you mistype a number - int.Parse will throw an exception.

Second, look at your code:
C#
if(a <= 0)
    do
        Console.WriteLine("Number must be greater than 0");
    while (a > 0) ;

If you value is greater than zero it won't even get to the loop!
And if it did, all it would do is print the same line forever...

Probably what you want is something like:
C#
if (a > 0)
   {
   while (a > 0)
      {
      // Do something
      ...
      a--;
      }
   }
else
   {
   ...

Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: help me in this code Pin
Ratul Thakur2-Apr-16 4:15
Ratul Thakur2-Apr-16 4:15 
AnswerRe: help me in this code Pin
Ratul Thakur2-Apr-16 3:52
Ratul Thakur2-Apr-16 3:52 
GeneralRe: help me in this code Pin
Sascha Lefèvre2-Apr-16 4:50
professionalSascha Lefèvre2-Apr-16 4:50 
GeneralRe: help me in this code Pin
Ratul Thakur2-Apr-16 6:33
Ratul Thakur2-Apr-16 6:33 
GeneralRe: help me in this code Pin
F-ES Sitecore3-Apr-16 4:15
professionalF-ES Sitecore3-Apr-16 4:15 
GeneralRe: help me in this code Pin
Pete O'Hanlon3-Apr-16 4:51
mvePete O'Hanlon3-Apr-16 4:51 
GeneralRe: help me in this code Pin
F-ES Sitecore3-Apr-16 4:56
professionalF-ES Sitecore3-Apr-16 4:56 
GeneralRe: help me in this code Pin
Ratul Thakur3-Apr-16 7:46
Ratul Thakur3-Apr-16 7:46 
GeneralRe: help me in this code Pin
Sascha Lefèvre3-Apr-16 13:11
professionalSascha Lefèvre3-Apr-16 13:11 
GeneralRe: help me in this code Pin
F-ES Sitecore3-Apr-16 22:38
professionalF-ES Sitecore3-Apr-16 22:38 
JokeRe: help me in this code Pin
Pete O'Hanlon3-Apr-16 22:57
mvePete O'Hanlon3-Apr-16 22:57 
AnswerRe: help me in this code Pin
Sascha Lefèvre2-Apr-16 5:10
professionalSascha Lefèvre2-Apr-16 5:10 
GeneralRe: help me in this code Pin
OriginalGriff2-Apr-16 6:16
mveOriginalGriff2-Apr-16 6:16 
GeneralRe: help me in this code Pin
Mycroft Holmes2-Apr-16 13:32
professionalMycroft Holmes2-Apr-16 13:32 
GeneralRe: help me in this code Pin
Sascha Lefèvre2-Apr-16 14:15
professionalSascha Lefèvre2-Apr-16 14:15 
GeneralRe: help me in this code Pin
Mycroft Holmes2-Apr-16 16:32
professionalMycroft Holmes2-Apr-16 16:32 
AnswerRe: help me in this code Pin
Suresh73-Apr-16 5:55
Suresh73-Apr-16 5:55 
QuestionInput string was not in a correct format as output in c# console application Pin
KittoKy2-Apr-16 1:48
KittoKy2-Apr-16 1:48 
AnswerRe: Input string was not in a correct format as output in c# console application Pin
OriginalGriff2-Apr-16 2:25
mveOriginalGriff2-Apr-16 2:25 
QuestionWrite/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib2-Apr-16 0:06
Mahbubur Rahman Rajib2-Apr-16 0:06 
AnswerRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
OriginalGriff2-Apr-16 0:09
mveOriginalGriff2-Apr-16 0:09 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib2-Apr-16 0:13
Mahbubur Rahman Rajib2-Apr-16 0:13 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
OriginalGriff2-Apr-16 0:19
mveOriginalGriff2-Apr-16 0:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.