Click here to Skip to main content
15,887,471 members
Home / Discussions / C#
   

C#

 
GeneralRe: problem in while and for loops Pin
Dr.Sammer9-Feb-06 11:00
Dr.Sammer9-Feb-06 11:00 
GeneralRe: problem in while and for loops Pin
User 66589-Feb-06 11:07
User 66589-Feb-06 11:07 
GeneralRe: problem in while and for loops Pin
Dr.Sammer9-Feb-06 11:10
Dr.Sammer9-Feb-06 11:10 
GeneralRe: problem in while and for loops Pin
User 66589-Feb-06 11:13
User 66589-Feb-06 11:13 
GeneralRe: problem in while and for loops Pin
Dr.Sammer9-Feb-06 11:19
Dr.Sammer9-Feb-06 11:19 
GeneralRe: problem in while and for loops Pin
User 66589-Feb-06 11:22
User 66589-Feb-06 11:22 
GeneralRe: problem in while and for loops Pin
Dr.Sammer9-Feb-06 11:26
Dr.Sammer9-Feb-06 11:26 
GeneralRe: problem in while and for loops Pin
LongRange.Shooter10-Feb-06 2:14
LongRange.Shooter10-Feb-06 2:14 
First: here is your code:
<br />
int numb;<br />
long fac = 1;<br />
Console.WriteLine("Enter a number :");<br />
numb = Int32.Parse(Console.ReadLine());<br />
<br />
for ( int numb; numb >0; numb--)<br />
{<br />
fac*=numb--;<br />
}<br />


Now look at what you are doing. int numb; defines a new object numb that is an integer.
numb = blah sets that integer to a number entered by the user.

for (int numb; numb>0; numb--) creates a new instance of numb which (since it is not nullable) gets a new value of 0. So what does your conditional do when it encounters that 0 value? My guess is you always get an answer of 1. Why? (look at it and answer this yourself)

So now you should be able to figure it out...that you need to change your initial storage name (ie. not numb) then set your for loop value int numb to the value you established in the Console.Read function.

There are 10 kinds of people in the world.

Those that read binary...

...and those who don't.

QuestionArray declaration without specifying the size. Pin
emran8349-Feb-06 10:38
emran8349-Feb-06 10:38 
AnswerRe: Array declaration without specifying the size. Pin
Judah Gabriel Himango9-Feb-06 10:46
sponsorJudah Gabriel Himango9-Feb-06 10:46 
GeneralRe: Array declaration without specifying the size. Pin
emran8349-Feb-06 11:06
emran8349-Feb-06 11:06 
GeneralRe: Array declaration without specifying the size. Pin
Judah Gabriel Himango9-Feb-06 11:22
sponsorJudah Gabriel Himango9-Feb-06 11:22 
GeneralRe: Array declaration without specifying the size. Pin
emran8349-Feb-06 11:53
emran8349-Feb-06 11:53 
GeneralRe: Array declaration without specifying the size. Pin
Judah Gabriel Himango9-Feb-06 12:06
sponsorJudah Gabriel Himango9-Feb-06 12:06 
AnswerRe: Array declaration without specifying the size. Pin
Guffa9-Feb-06 22:16
Guffa9-Feb-06 22:16 
QuestionTriggerring Event Handler and pass variable in PARENT FORM from Child FORM Pin
emran8349-Feb-06 10:30
emran8349-Feb-06 10:30 
Question.NET Framework 2.0 Pin
Manu_819-Feb-06 10:21
Manu_819-Feb-06 10:21 
AnswerRe: .NET Framework 2.0 Pin
emran8349-Feb-06 10:33
emran8349-Feb-06 10:33 
AnswerRe: .NET Framework 2.0 Pin
Judah Gabriel Himango9-Feb-06 10:42
sponsorJudah Gabriel Himango9-Feb-06 10:42 
QuestionDesign time problems with custom TreeView and private node class Pin
Pedro S Ferreira9-Feb-06 10:18
Pedro S Ferreira9-Feb-06 10:18 
AnswerRe: Design time problems with custom TreeView and private node class Pin
leppie9-Feb-06 10:51
leppie9-Feb-06 10:51 
GeneralRe: Design time problems with custom TreeView and private node class Pin
Pedro S Ferreira9-Feb-06 11:01
Pedro S Ferreira9-Feb-06 11:01 
AnswerRe: Design time problems with custom TreeView and private node class Pin
Pedro S Ferreira10-Feb-06 5:49
Pedro S Ferreira10-Feb-06 5:49 
Questionmenubar on a customised windows' form Pin
dlinks9-Feb-06 8:39
dlinks9-Feb-06 8:39 
QuestionConverting String to Int Pin
zaboboa9-Feb-06 8:34
zaboboa9-Feb-06 8:34 

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.