First I want to start out saying I am a student, and new to coding. So, I apologize in advance for my general lack of knowledge in this dept....
I am trying to write code that will read in integers and store them in a multidimensional array. The integers are points on a graph, x & y values. Also, I want the array size to be a variable the user will input (as in the number of points the user will be inputting -- points[numPoints][2]). This is what I have so far:
#include <stdio.h>
int main()
{
int numPoints=0, row, colm;
int points[numPoints][2];
printf("This program will read in a number of points, and calculate the distance between them.\n");
printf("It will also calculate the total distance between the first point, and the last point.\n");
printf("\nHow many points will you be entering?\n");
scanf(" %d", &numPoints);
printf("Please enter each point individually.\nExample(x & y values shown):\nx y\n3 5\n-2 10\netc...\nPlease enter your points now (press 'Enter' after each point):\n");
for (row = 0; row<numPoints; row++)
{
for (colm = 0; colm<2; colm++)
{
scanf("%d", &points[row][colm]);
}
}
printf("These are the points recorded:\n");
for (row = 0, colm=0; row<numPoints; row++)
{
printf("(%d,%d)\n", points[row][colm],points[row][colm+1]);
}
return 0;
}
I have run it a few times now, and this is the output I am getting. It is either not storing the numbers correctly, or it is not printing them correctly.
This program will read in a number of points, and calculate the distance between them.
It will also calculate the total distance between the first point, and the last point.
How many points will you be entering?
4
Please enter each point individually.
Example(x & y values shown):
x y
3 5
-2 10
etc...
Please enter your points now (press 'Enter' after each point):
1 2
3 4
5 6
7 8
These are the points recorded:
(1,2)
(3,4)
(6,31)
(1,8)
Program ended with exit code: 0
Can anyone please tell me what I am doing wrong?
Thank you