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