undeclared variable problem

This is a discussion on undeclared variable problem within the C++ Programming forums, part of the General Programming Boards category; I am having a bit of problem understanding why the compiler is shouting at me that I have an undeclared ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    66

    undeclared variable problem

    I am having a bit of problem understanding why the compiler is shouting at me that I have an undeclared variable.

    This bit of code works:
    Code:
    void line(int n, char c)
    {
      cout << callnumber << ": " ;
    
      for (int i = 0; i < n; i++)
        {
          cout << c ;
        }
    
      cout << endl ;
    }
    But this code gives me the following errors :

    barchart.cc: In function `void hyphen(int)':
    barchart.cc:7: `i' undeclared (first use this function)
    barchart.cc:7: (Each undeclared identifier is reported only once
    barchart.cc:7: for each function it appears in.)
    Code:
    void hyphen(int a)
    {
      for (i = 0; i < a; i++)
        {
          cout << "-" ;
        }
      cout << endl ;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    for (int i = 0; i < n; i++)
    for (i = 0; i < a; i++)
    Guess what this does...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    66
    Thank you.

    As always, one is blind as a bat to the obvious.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Problem getting the input from a temp variable into the Array
    By hello_moto in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2006, 12:50 AM
  3. Problem with a char variable set as a letter
    By 7smurfs in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2004, 12:25 PM
  4. Strange variable problem
    By Mithoric in forum Windows Programming
    Replies: 9
    Last Post: 06-19-2004, 03:34 AM
  5. Peculiar Problem with char variable in C Language
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-31-2001, 03:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21