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