Thread: NEED HELP! I'm stuck.

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    2

    NEED HELP! I'm stuck.

    I'm trying to solve this question but I'm stuck.

    Q) Write a function, getData(arrX[], arrY[], numValues), that accepts two arrays and an integer value. The function will read from user a set of data points (x and y) and populate the two arrays accordingly - arrX stores x coordinates, arrY stores y coordinates. The function will repeatedly read x and y until user enters -999 for x value and the function returns the number of data points read and update the numValues with the number of x,y points read from the file. The function does not return any value.

    My solution:

    Code:
    #include <stdio.h>
    void getData(double arrX[], double arrY[], int numValues);
    int main(void)
    {
      double x, y;
      int numValues;
    
      printf("Enter x, y: ");
      scanf("%lf %lf", &x, &y);
      getData(&x, &y, numValues);
      return 0;
    }
    
    void getData(double arrX[], double arrY[], int numValues)
    {
      while (1) {
        double x, y;
        printf("Enter x, y: ");
        if (x == -999) {
          break;
        } else {
          arrX[numValues] = x;
          arrY[numValues] = y;
          numValues += 1;
        }
      }
    }
    Last edited by Salem; 2 Weeks Ago at 03:21 PM. Reason: Removed crayola

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    Do you realize that in main() x and y are single doubles, not two arrays of double as your function expects?

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    2
    Hi, I just started my c programming so I'm really bad at it.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    So how does "I'm really bad at it" relate to the problem at hand?

    What exactly don't you understand?

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    3,675
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck and looking for help
    By The_dr in forum C++ Programming
    Replies: 2
    Last Post: 03-17-2017, 09:12 AM
  2. Help please im stuck
    By ItsMeHere in forum C Programming
    Replies: 7
    Last Post: 06-15-2006, 04:07 AM
  3. very stuck please help!
    By dac in forum C++ Programming
    Replies: 25
    Last Post: 05-07-2006, 02:45 AM
  4. ok im stuck...
    By gL_nEwB in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2006, 06:12 PM
  5. Stuck
    By bumfluff in forum C++ Programming
    Replies: 40
    Last Post: 04-01-2006, 09:11 AM

Tags for this Thread