-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
30 lines (26 loc) · 761 Bytes
/
main.c
File metadata and controls
30 lines (26 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>
void print_help() {
printf("Usage:\n");
printf("sumcli <first number> <second number>\n");
printf("\n");
printf("first number is the first number to sum\n");
printf("second number is the second number to sum\n");
}
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Not enough arguments! You need to enter exactly two numbers\n");
print_help();
return 1;
}
if (argc > 3) {
printf("Too much arguments! You need to enter exactly two numbers\n");
print_help();
return 1;
}
double first = atof(argv[1]);
double second = atof(argv[2]);
double sum = first + second;
printf("The sum is %.2f\n", sum);
return 0;
}