if else was replaced by switch. Added handling for an unknown flag.

This commit is contained in:
Alexander Andreev 2023-09-17 23:49:06 +04:00
parent 18a593e800
commit 64bcbfbc45
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -10,12 +10,10 @@ int main(const int argc, const char *const *const argv) {
interval_t interval = 0; interval_t interval = 0;
int res = parse_arguments(argc, argv, &price, &wattage, &interval); int res = parse_arguments(argc, argv, &price, &wattage, &interval);
if (res != 0) { switch (res) {
if (res == 1) case 1: print_usage(); exit(0);
print_usage(); case 2: print_version(); exit(0);
else if (res == 2) case 99: fputs("Unknown flag provided.\n", stderr); print_usage(); exit(1);
print_version();
exit(0);
} }
printf("%.2Lf\n", (price * wattage) * interval); printf("%.2Lf\n", (price * wattage) * interval);