I'm having an error as you can see in the image I attatched. I also attached the only c file of this program in which the error resides.
I'm having an error as you can see in the image I attatched. I also attached the only c file of this program in which the error resides.
How many times do you think this for loop will run.
Assume i does not equal a. Or, let a be equal to 4.
Hint: Do you know what "==" means?
If hint is not enough read http://www.cprogramming.com/tutorial/c/lesson3.htmlCode:for(i=0; i == a; i++)
Tim S.
Last edited by stahta01; 10-30-2011 at 05:14 PM.
Stop and think what would happen if someone put in -1 ....
Oh thank you, I discovered my error. I should have put:
Code:for(i=0; i < a; i++) { printf("Your Number(s): "); scanf("%d", &l); int b = l + b; }
Last edited by mmario10; 10-31-2011 at 03:59 AM.
I solved that error, but when i reach the answer, it still gives me 0!!
Have a look at this line. It creates a new variable named b, which happens to be initialized using the value of b at another scope. The one created inside the loop will not exist outside it.
Using a variable named 'l' is also an extremely bad idea, only justified by laziness. It is quite difficult to distinguish an 'l' (lowercase L) from a '|' (bitwise or). It can, depending on screen characteristics, be difficult to distinguish from other characters as well.
Last edited by grumpy; 10-31-2011 at 04:20 AM.
Fixed the error, thanks. And changed the 'l' variable to 'r'. Intead of doing:I did:Code:int b = r + b;Code:b = r + b;