Added some safeguards.

This commit is contained in:
Nicolás A. Ortega 2016-12-01 20:55:54 +01:00
parent 2301be1637
commit 573343de8f
No known key found for this signature in database
GPG Key ID: 614272579C2070D1

View File

@ -12,10 +12,20 @@ int main(void) {
printf("Enter \"min, max\": ");
scanf("%lf, %lf", &a, &b);
if(a > b) {
fprintf(stderr, "`min' cannot be larger than `max'.\n");
return 1;
}
unsigned int parts;
printf("Number of parts: ");
scanf("%u", &parts);
if(parts == 0) {
fprintf(stderr, "`parts' must at least be 1.\n");
return 1;
}
double lRect, rRect, mRect, trap, simp;
lRect = rRect = mRect = trap = simp = 0;
for(unsigned int i = 0; i < parts; ++i) {