Skip to content

Commit 9ef0acd

Browse files
committed
if statement
1 parent cd9d3c3 commit 9ef0acd

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

01_SimpleCApp/SimpleCApp.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33

44
int32_t f(int32_t x);
55
int scan_x(int32_t* x);
6+
void execute_print(int32_t x);
67
void print_fx(int32_t x, int32_t y);
78

89
int main()
910
{
10-
// (I)
11-
int32_t x = 0;
11+
int32_t x;
1212
int result = scan_x(&x);
13-
printf("Read %i parameters from user input. ", result);
14-
15-
// (P)
16-
int32_t y1 = f(1 * x);
17-
int32_t y2 = f(2 * x);
18-
int32_t y3 = f(3 * x);
19-
int32_t y4 = f(4 * x);
20-
21-
// (O)
22-
print_fx(1 * x, y1);
23-
print_fx(2 * x, y2);
24-
print_fx(3 * x, y3);
25-
print_fx(4 * x, y4);
13+
if (result == 1)
14+
{
15+
execute_print(x);
16+
}
17+
else if (result == EOF)
18+
{
19+
printf("IO Error!");
20+
}
21+
else
22+
{
23+
printf("The input must be a number!");
24+
}
2625
}
2726

2827
int32_t f(int32_t x)
@@ -36,6 +35,19 @@ int scan_x(int32_t* x)
3635
return scanf_s("%i", x);
3736
}
3837

38+
void execute_print(int32_t x)
39+
{
40+
int32_t y1 = f(1 * x);
41+
int32_t y2 = f(2 * x);
42+
int32_t y3 = f(3 * x);
43+
int32_t y4 = f(4 * x);
44+
45+
print_fx(1 * x, y1);
46+
print_fx(2 * x, y2);
47+
print_fx(3 * x, y3);
48+
print_fx(4 * x, y4);
49+
}
50+
3951
void print_fx(int32_t x, int32_t y)
4052
{
4153
printf("f(%i) = %i, ", x, y);

0 commit comments

Comments
 (0)