Thread: Using a Single Char. to show increase or decrease

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Using a Single Char. to show increase or decrease

    I have a code with 3 columns. The 2nd. columns should contain a single character that shows if the numbers in the 1st. column is increasing or decreasing.

    In other words, if row 2 is greater than row 1 in column 1 then put an "D" else put in an "I".

    MeanRelativeError id percentage
    0.644952 I 0.00043
    0.618256 I 0.006566
    0.615946 D -0.000549
    0.615686 D 0.004135
    0.621896 I 0.006141

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    I guess I sort of get what your trying to say, but not entirely.

    When you say "put", are you writing to a variable, saving to a file, printing to the console, etc?

    And when you say that you have code with three columns, do you mean you have multi-dimensional array?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Using a Single Char in C programming

    My code creates an output file and from the fprintf option. A variable is created to form another column that column is supposed to look at the prior column and put a single character (I) in that column if the row below is greater than the row above else if lesser put a "D" character.

    Hope that helps.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Keep the previous value around somewhere. if newvalue > oldvalue print I else print D. Then change oldvalue to newvalue and get a new newvalue from the table.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Single Character

    Thank you for responding. That is exactly what I am trying to do but I do not know the code to use....

    Does anyone know what code to use?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by youngdawny View Post

    Does anyone know what code to use?
    You are aware that "if" and "else" are C keywords?

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Single Char

    Yes - I am aware of "if" and "else". The problem I have is how to read the line and to check which of the tw rows is greater and use the character "I" or "D".

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And what's wrong with
    Code:
    if (lastrow < thisrow)
        printf("I");
    else
        printf("D");
    ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  3. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Extra printed stmts...why?
    By mangoz in forum C Programming
    Replies: 4
    Last Post: 12-19-2001, 07:56 AM