- Joined
- Oct 16, 2024
- Messages
- 1
- Reaction score
- 0
Hey, I was accepted to the University for programming major, even though I basically never programmed anything in my life before, however my first homework here is to make a program in which I write 3 coordinates ([x, y]) and the program should be able to calculate 3 more coordinates so with one of the new coordinates and the 3 I wrote there, it would make a rectangle, or any of its special form (square, rhombus, parallelogram) and then the program should decide whether the newly formed tetragonal is square, etc. However, I need the program to work even when I fill in the coordinates in these forms
[ 5, 0 ]
or when it’s all written in one line only
[10.5, 10.5] [12.5, 10.5][10.5, 15e+0]
or when I write it like this [3,
4
])
but my program automatically says it’s incorrect input and I can’t figure out how to make that work, I even tried ai, but it didn’t help me neither, so any help from a more experienced programmer would be greatly appreciated. Everything else should work just fine. I hope that my problem is understandable as English isn’t my first language
Here is the part of my program, where I fill in the coordinates:
int main(void) {
double ax, ay, bx, by, cx, cy;
double tolerance = 0.0000001;
char input[100];
printf("Bod A:\n");
fgets(input, sizeof(input), stdin);
if (sscanf(input, "[%lf, %lf]", &ax, &ay) != 2) {
printf("Nespravny vstup.\n");
return 1;
}
printf("Bod B:\n");
fgets(input, sizeof(input), stdin);
if (sscanf(input, "[%lf, %lf]", &bx, &by) != 2) {
printf("Nespravny vstup.\n");
return 1;
}
printf("Bod C:\n");
fgets(input, sizeof(input), stdin);
if (sscanf(input, "[%lf, %lf]", &cx, &cy) != 2) {
printf("Nespravny vstup.\n");
return 1;
}
"Bod A" means coordinate A in my language and so on, and "Nespravny vstup" means incorrect input
[ 5, 0 ]
or when it’s all written in one line only
[10.5, 10.5] [12.5, 10.5][10.5, 15e+0]
or when I write it like this [3,
4
])
but my program automatically says it’s incorrect input and I can’t figure out how to make that work, I even tried ai, but it didn’t help me neither, so any help from a more experienced programmer would be greatly appreciated. Everything else should work just fine. I hope that my problem is understandable as English isn’t my first language
Here is the part of my program, where I fill in the coordinates:
int main(void) {
double ax, ay, bx, by, cx, cy;
double tolerance = 0.0000001;
char input[100];
printf("Bod A:\n");
fgets(input, sizeof(input), stdin);
if (sscanf(input, "[%lf, %lf]", &ax, &ay) != 2) {
printf("Nespravny vstup.\n");
return 1;
}
printf("Bod B:\n");
fgets(input, sizeof(input), stdin);
if (sscanf(input, "[%lf, %lf]", &bx, &by) != 2) {
printf("Nespravny vstup.\n");
return 1;
}
printf("Bod C:\n");
fgets(input, sizeof(input), stdin);
if (sscanf(input, "[%lf, %lf]", &cx, &cy) != 2) {
printf("Nespravny vstup.\n");
return 1;
}
"Bod A" means coordinate A in my language and so on, and "Nespravny vstup" means incorrect input