C++: Taking numbers from 2 functions and taking the average of them in another function

How would you make a function where the function takes the average of two numbers from 2 other different functions.

1
2
3
4
5
double averageWords(Counts& counts)
{
   double average;
   average = counts.countSentences/counts.countWords;
}
Last edited on
Can you explain a bit more?

1
2
3
void gaz() {
  auto average = ( foo() + bar() ) * 0.5;
}

The gaz is a function.
The gaz calculates the average of two numbers.
One number is received from function foo.
Other number is received from function bar.

No, I would probably not do it like that.
My program is taking a text file and reading how many words, sentences, characters, simple sentences, average words per sentence, and how many sentences containing "to be". I made them into structures called Counts. I want to be able to group the results of the two functions below and divide them.
Function for words
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int countWords(Counts& counts, char line[])
{
  counts.countWords=0;
  char c;
  int i=0;
  while (line[i]!='\0')
  {
    c= line[i];
    if (isspace(c))
    {
    counts.countWords++;
    }
  i++;
  }
}


Function for Sentences
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int countSentences(Counts& counts, char line[])
{
counts.countSentences=0;
int i=0;
char p=0;
while (line[i] !='\0')
{
    p=line[i];
    if((p == '.')||(p == '?')||(p == '!'))
    {
        counts.countSentences++;
    }
i++;
}
}
Last edited on
Topic archived. No new replies allowed.