I did a basic function of squaring (exercise of a book), and I use a variable named aux
and use it to compute the square power value, but the compiler claims that aux
does not is initialized, I would like to understand why and how to resolve this issue.
/*fazer uma função que calcule e retorne o valor de um número ao quadrado*/
#include <stdlib.h>
#include <iostream>
using namespace std;
double square (double);
int main ()
{
double x;
cout << "Digite um numero:\n";
cin >> x;
system ("clear");
cout << "O numero " << x << " elevado ao quadrado eh: " << square (x) << "\n";
}
double square (double x)
{
int i;
double aux;
for (i = 0; i < x; i++)
{
aux = aux + x;
}
return aux;
}