Help, I’m not sure where this problem is wrong; when I run it myself, the answer seems to be the same as theirs.
#include <cstdio.h>
#include <cstdlib.h>
#include <cstring.h>
struct book {
char title[31];
float price;
};
int main() {
int n;
scanf("%d", &n);
if(n <= 0 || n >= 10) {
return 0;
}
struct book books[n];
for (int i = 0; i < n; i++) {
getchar(); // read newline character
fgets(books[i].title, sizeof(books[i].title), stdin);
scanf("%f", &books[i].price);
}
if(n == 1) {
printf("%.2f, %s", books[0].price, books[0].title);
return 0;
}
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (books[j].price < books[j + 1].price) {
struct book temp = books[j];
books[j] = books[j + 1];
books[j + 1] = temp;
}
}
}
printf("%.2f, %s", books[0].price, books[0].title);
printf("%.2f, %s", books[n - 1].price, books[n - 1].title);
return 0;
}


But it still prompts the minimum n, answer is wrong.