Problems building a "command-line" calculator

• 10-30-2011
mmario10
Problems building a "command-line" calculator
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.
• 10-30-2011
stahta01
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?
Code:

`for(i=0; i == a; i++)`
If hint is not enough read http://www.cprogramming.com/tutorial/c/lesson3.html

Tim S.
• 10-31-2011
CommonTater
Stop and think what would happen if someone put in -1 ....
• 10-31-2011
mmario10
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;                 }```
• 10-31-2011
mmario10
I solved that error, but when i reach the answer, it still gives me 0!!
• 10-31-2011
grumpy
Quote:

Originally Posted by mmario10
Code:

`int b = l + b;`

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.
• 10-31-2011
mmario10
Fixed the error, thanks. And changed the 'l' variable to 'r'. Intead of doing:
Code:

` int b = r + b;`
I did:
Code:

` b = r + b;`