if else was replaced by switch. Added handling for an unknown flag.
This commit is contained in:
parent
18a593e800
commit
64bcbfbc45
12
src/main.c
12
src/main.c
@ -10,13 +10,11 @@ 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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user