Forming a maths expression that references array elements

This is a discussion on Forming a maths expression that references array elements within the C Programming forums, part of the General Programming Boards category; Thanks Mats, it works well now for single digits but it doesn't accept double digits. Could you give me more ...

  1. #16
    Registered User
    Join Date
    Jul 2007
    Posts
    35
    Thanks Mats, it works well now for single digits but it doesn't accept double digits. Could you give me more hint of how to make it more general. I'm trying to read up the struct and enum you mentioned about

  2. #17
    Registered User
    Join Date
    Jul 2007
    Posts
    35
    Thanks Mats it's working now for single digits, I've also added a code to reconvert the array back to numeric. Could you assist me to make it more general so it can accept double digits using the enum and struct you talked about. I'm equally trying to read it up.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    structures is a way to "group data together".
    for example:

    Code:
    struct employee {
       char name[25];
       char role[20];
       int yearofbirth;
       int salary;
    };
    
     // You can then create an array of "employees":
    struct employee staff[100];
    structs are pretty similar to classes in C++ too - in fact, you can use struct and class ALMOST interchangably in C++ - there are subtle differences that make one better than the other in a particular situation, but that's best left for when you start learning about C++ - and there's much more important things to learn right now. [1]

    enum is a way to "make a list of things that you can use to count/identify", such as you could declare a range of colours:

    Code:
    enum { violet, purple, red, yellow, green, blue, white, black } colours;
    You can then use these in your code to make it much clearer what you mean. Essentially, the above enum is the same as defining constants for the individual colours and using those constants - just an easier way to do it.

    [1] In general, which language you use is pretty unimportant. Knowing how to program is a generic skill, and whilst some languages are better for some things than others, most have pretty much the same common ways to operate, and learning how to program in GENERAL is more important than which particular language you do it in.

    --
    Mats

  4. #19
    Registered User
    Join Date
    Jul 2007
    Posts
    35
    Ok thanks, I'll try to crack it.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  2. using realloc for a dynamically growing array
    By broli86 in forum C Programming
    Replies: 10
    Last Post: 06-27-2008, 06:37 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 10:48 AM
  5. A simple question about selecting elements in an array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:37 PM

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