Can u help solve this problem in c++?

Make a program in C ++ to calculate the quadratic mean of n values entered by the user. The quadratic mean is given by the following equation:

https://uploaddeimagens.com.br/imagens/equacao-jpg--2

The program should read the value of n and the n values of x.

What's wrong with my code:

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
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int n;
    int x;
    int soma;
    double xq;

    cout << "Digite o valor de n: ";
    cin >> n;

    soma = 0;
    for(int i = 0; i < n; i++){
        cout << "Digite o valor de x" << i + 1 << ": ";
        cin >> x;
        soma += x^2;
    }

    xq = sqrt(soma/n);

    cout << "\nO valor de Xq e: " << xq << endl;

    return 0;
}
Last edited on
soma += x^2;
Do you know the meaning of ^ in C++ ? It's a bitwise operator.
I guess you want to do soma += x * x;
Topic archived. No new replies allowed.