Thread: Storing input values into Array

  1. #1
    Registered User
    Join Date
    Nov 2011

    Storing input values into Array

    Hi all,

    I'm very new to C programming, and I'm having some difficulty with the program I want to build...

    What it needs to be is a program which asks the user for the number of resistors to be tested, then ask for the resistor values, then putting these values into an array. So far I've done this;

    #include <stdio.h>
    #include <math.h>
    int main (void)
             int n;
             int x;
             /* Header of Program */
             printf ("\t\t The Resistor Company\n\n\t\t  Resistance Checker\n\t\t  __________________\n");
             /* Request Number of Resistors to test - Do While Loop*/
             do {
             printf ("\nHow many resistors would you like to enter?\n[Enter a value between 2 and 10]\n\n");
             scanf ("%d", &n);
             if (n < 2 || n > 10)
                { printf ("\nYou have entered a number out of range.\nPlease re-enter!\n"); }
             }   while (n < 2 || n > 10);
                printf ("\nNumber of resistors to test: %d\n\n", n);
             /* Request Resistor Values */
             printf ("\nResistor Value 1: ");
             scanf ("%d", x);
             /* End of Program */
             system ("PAUSE");
             return (0);
    It's just the beginning I know, not really sure where to go from here. The resistor values need to be asked for, such that if the user input 5 resistor values to test, resistor values 1-5 need to be asked for. Then, each value need to be put into an array for future calculations (such as smallest resistor, largest resistor, mean resistance etc.).

    The resistor values also must be between 1x10^-3 ohms and 1x10^6 ohms, i.e. between 1mOhm and 1MOhm.

    Hope somebody can help with this?

    Thanks in advance!

    P.S. This is a homework assignment, I'm not expecting anyone to do it for me but just explain how I could do it and give me a few pointers. This would be very much appreciated
    Last edited by nelly26; 11-30-2011 at 09:36 AM. Reason: Clarity

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    It looks there is a upper limit on the number of values that could be entered -- if so, just use an int array big enough for that many. If not, you will have to malloc() an array of n size.

    The use a for() loop with n.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing values in an array
    By kpop in forum C Programming
    Replies: 3
    Last Post: 04-12-2011, 01:46 PM
  2. Storing input values while iterating
    By russel1013 in forum C Programming
    Replies: 11
    Last Post: 07-29-2008, 08:32 AM
  3. Storing values from Edit Box into an array
    By E_I_S in forum C++ Programming
    Replies: 10
    Last Post: 06-05-2008, 06:24 AM
  4. Storing values from an array pointer
    By newatc in forum C Programming
    Replies: 21
    Last Post: 01-07-2008, 06:46 AM
  5. int array isn't storing proper values.
    By System_159 in forum C++ Programming
    Replies: 1
    Last Post: 08-31-2006, 08:55 AM