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;
}
}
}