-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmean_exames.c
More file actions
71 lines (59 loc) · 1.39 KB
/
mean_exames.c
File metadata and controls
71 lines (59 loc) · 1.39 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "isvalid.h"
#define buffer_size 256
float media_alunos(char const *argv[], int size_arr)
{
float media = 0;
for (int index = 0; index < size_arr; index++)
{
/* A função atof converte uma String (sequência de caracteres) em Float */
media += atof(argv[index + 1]);
}
return media / size_arr;
}
float iterative_mode()
{
int index = 0;
float media_notas = 0;
char buffer[buffer_size];
puts("Para finalizar o modo iterativo digite: q");
while (true)
{
printf("Digite um numero:");
scanf(" %s", buffer);
if (strcmp(buffer, "q") == 0)
{
break;
}
else if (checker_type(buffer))
{
media_notas += atof(buffer);
index += 1;
}
else
{
puts("Por favor digite numeros!");
}
}
return media_notas / index;
}
int main(int argc, char const *argv[])
{
if (argc == 1)
{
puts("Falta passar os parâmetros!");
return EXIT_FAILURE;
}
int input_size = argc - 1;
if (check_input_isvalid(argv, input_size))
{
printf("Media-> %0.2f\n", media_alunos(argv, input_size));
return EXIT_SUCCESS;
}
puts("Uma entrada invalida ocorreu no CLI. Experimente o modo iteraivo.");
printf("Media-> %0.2f\n", iterative_mode());
return EXIT_SUCCESS;
}