Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool s1(float &average){
- bool result = true;
- char filename[80];
- printf("Enter your filename: ");
- scanf("%s", &filename);
- FILE *file = fopen(filename, "r");
- if(file == NULL)
- result = false;
- else{
- float current = 0.0f, s = 0.0f;
- int count = 0;
- while(!feof(file)){
- if(fscanf(file, "%f", ¤t)){
- s = sum(s, current);
- ++count;
- }
- }
- if(count == 0)
- result = false;
- else
- average = s / (1.0f * count);
- }
- fclose(file);
- return result;
- }
- float sum(float &s, float ¤t){
- return (s + current);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement