summaryrefslogtreecommitdiff
path: root/userspace/add.c
blob: 3a624be44c44e9a31766c36f2aa79d2a2a6c9ce5 (plain)
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
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "../fs/fs.h"

int main(int argc, char **argv) 
{

    int sum=0;
    int i=0;

    char *buf=malloc(256);
    puts("\n*** fools calculator ***");
    
    while(1)
    {
	printf("enter numer (or 'exit' to finish) %i: ",i+1);
        fgets(buf,255,stdin);

	if(buf[1]=='x')break;

	i++;
	sum+=atoi(buf);
    }

    if(i!=0)
    {
	puts("--------");
	printf("sum = %i \n",sum);
	printf("avg = %i \n\n",sum/i);
    }

    return 0;
}