Undeclared identifier uppur, please help me!

This is a discussion on Undeclared identifier uppur, please help me! within the C Programming forums, part of the General Programming Boards category; Hello, Do you know what is wrong with this? Code: /* print fahr-celc table for fahr = 0, 10, 20, ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    1

    Question Undeclared identifier uppur, please help me!

    Hello,

    Do you know what is wrong with this?
    Code:
    /* print fahr-celc table for fahr = 0, 10, 20, ..., 100 */
    
    
    int main (void)
    {
    int celc, fahr;
    int lower, upper, step;
    
    
    lower = 0;        /* lower limit of temperature scale */
    upper = 100;    /* upper limit */
    step = 10;        /* step size */
    
    
    fahr = lower;
    while (fahr <= uppur);    
        {
        celc = 5*(fahr-32)/9;
        printf("%d\t%d\n", fahr, celc);
        fahr = fahr + step;
        }
    }
    When I press execute, pelles c says:
    Building main.obj.
    D:\Documenten\Mijn_documenten\c programma's van mij\derde project\main.c(37): error #2048: Undeclared identifier 'uppur'.
    *** Error code: 1 ***
    Done.

    I don't know what is wrong with this.

    Please help me.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,678
    Check your spelling. Where do you define a variable with the name uppur?

    Jim

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,197
    Check your spelling:

    Code:
    int lower, upper, step;
    
    // ...
    
    while (fahr <= uppur);
    When you fix this and see that the program appears to do nothing, think about whether or not you really want that semi-colon at the end of your "while()".

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,678
    Also the following will probably not produce your desired results:
    Code:
    celc = 5*(fahr-32)/9;
    You are using integer math, there are no fractions in integer math. So something like 1/2 will yield zero, with the fractional part discarded.

    Jim

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    333
    Quote Originally Posted by jimblumberg View Post
    Also the following will probably not produce your desired results:
    Code:
    celc = 5*(fahr-32)/9;
    You are using integer math, there are no fractions in integer math. So something like 1/2 will yield zero, with the fractional part discarded.

    Jim
    The other issue is that C uses BODMAS. So divisions happen before multiplications, and the expression becomes 5*((fahr-32)/9). fahr is rounded down to the lowest multiple of 5. If you write (5*(fahr-32))/9 instead, you will get what is probably an acceptably accurate integer result.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    http://www.malcolmmclean.site11.com/www

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by Malcolm McLean
    The other issue is that C uses BODMAS. So divisions happen before multiplications
    No, C has precedence rules akin to BODMAS, but not quite the same. In particular, the / and * operators have the same precedence. Furthermore, precedence determines grouping, not necessarily the order of evaluation.

    Quote Originally Posted by Malcolm McLean
    the expression becomes 5*((fahr-32)/9).
    No, the grammar is such that * and / are left associative. Hence the expression 5*(fahr-32)/9 is equivalent to (5*(fahr-32))/9 rather than 5*((fahr-32)/9).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'complex' undeclared identifier
    By mvanrijnbach in forum Windows Programming
    Replies: 6
    Last Post: 03-29-2010, 08:04 AM
  2. Undeclared Identifier
    By Kayoss in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2006, 10:48 AM
  3. 'setioflags' undeclared identifier?
    By ForlornOdium in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2003, 03:44 AM
  4. 'undeclared identifier' in tapi
    By schez in forum Windows Programming
    Replies: 2
    Last Post: 10-31-2003, 09:06 PM
  5. Undeclared Identifier
    By Witch_King in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2001, 12:58 PM

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