A warning: I know there must be an easier way to make this script work. But I'm a newb who has a very hard time wrapping my head around programming and I don't want to destroy my thinking by looking at the answers.

Any who. I'm having a bunch of undeclared variable issues in my script. I'm not sure how to make them "universal" so that it stops being such a nuissance.

Any examples or advice on how to make it work for my script ?


enter image description here

I think the image above is the only functional part of my script.

Here's the broken part:

enter image description here

enter image description here

also I realized that the last line should be %i since i'm adding integers. but its too cumbersome a task to recapture that image.

  • In the future, please cut and paste code and output into your questions. When you use images of screen shots, code can't be cut and pasted for testing and nobody is going to transcribe it. It can also be very difficult to read.
    – Cliff B
    Jan 4, 2018 at 3:13
  • Sorry about that and thanks.
    – SuperZumo
    Jan 5, 2018 at 2:24

1 Answer 1


I think you'd benefit from a thorough review of class material, particularly the discussion on variable scope.

The "undeclared" vars are really an issue of where they are declared. Remember that a variable only exists between the immediate pair of curly braces surrounding it. A var can go into and back out of a set of braces, but it will cease to exist after the closing curly brace that defines its scope. A visual example explains it better.

int main(void)
    int i;
       int j;
       // both i and j exist here.
    // j no longer exists, but i still does exist here.
// both i and j no longer exist here. 

Also, keep an eye on parentheses pairings ().

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Thanks for assuming I haven't thoroughly reviewed the class. Your explanation was much more precise than hours of review of class material.
    – SuperZumo
    Jan 5, 2018 at 2:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .