Invalid operands of type double to binary 'operator-'

I have an error in function 'double sd1 (double, double)'. Can someone give me some advice?

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
#include <iostream>
#include <cmath>

using namespace std;

double a (double s1, double s2, double s3, double s4);
double sd1 (double s1, double a);

int main()
{
    double s1, s2, s3, s4;
    char ans;
    do
    {
        cout << "Input four scores" << endl;
        cin >> s1>> s2>> s3 >>s4;
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        cout << "The average score is " << a(s1,s2,s3,s4);
        cout << "The standard deviations of the first values is " << sd1(s1,a(s1,s2,s3,s4));
        cout << "Do you wanna repeat?" << endl;
        cin >> ans;

    }
    while (ans=='y'||ans=='Y');
    return 0;
}
double a (double s1, double s2, double s3, double s4)
{
   return ((s1+s2+s3+s4)/4);
}
double sd1 (double s1, double a)
{
    return (sqrt(pow((sd1-a),2.0)));
}
1
2
3
4
5
double sd1 (double s1, double a)
{
    // return (sqrt(pow((sd1-a),2.0))); // sd1 is the name of the function
    return sqrt( pow( (s1-a), 2.0 ) ) ; // s1 is the name of the variable
}

Use names which convey meaning (for functions, variables, ... ) and we won't get into this kind of mess.
Oh I got it. It should be s1. Thanks
Topic archived. No new replies allowed.