I need a little assistance with finding the square roots of each number entered by the user in a array. I'll copy and paste what i have so far in my function, but i get an error when i try to run the program and it would say:

``````sqrt was not declared in the function
``````

Code:

``````void print_square_root (double values [size])
{
int index;
cout << "The square root of the numbers are:\n";
for (index = 0; index < size; index++)
{

values [index] =  sqrt (values [index]);
cout << "\n\n";
cout << showpoint << fixed << setprecision (2);
cout << setw (9) << values [index];
}
``````

Anyone with any suggestions on how i would get the square roots to work for each number in the array I would greatly appreciate it...Thank You

## All 3 Replies

How about posting a compilable example? Like, with your header includes and driver and the complete function so we can do more than just guess?

Ok here is what i believe your asking for. This is the rest of my program that i wrote along with the question that was asked of me to do.

1. Write a program that reads in 8 double values entered by the user. It should store the values in an array. It should print the original numbers, the squares of the original numbers and the square roots of the numbers. The values should be printed in width 9 with 2 digits after the decimal.

Define the following constant and functions to help solve the problem:

const int SIZE=8;

void print_numbers (double numbers );
void print_squares (double numbers );
void print_square_roots (double numbers );

Here is what a sample run of the program would look like:

Enter 8 numbers:
8.32 9.55 6 2.34 15.4 24 6.5 3.1

The numbers entered were:
8.32 9.55 6.00 2.34 15.40 24.00 6.50 3.10

The squares of the numbers are:
69.22 91.20 36.00 5.48 237.16 576.00 42.25 9.61

The square roots of the numbers are:
2.88 3.09 2.45 1.53 3.92 4.90 2.55 1.76

What i have so far:

``````#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;
const int size = 8;
void square_array (double values [size]);
void print_numbers (double values [size]);
void print_square_root (double values [size]);

int main(int argc, char *argv[])
{

const int size = 8;
double number;

double values [size];

print_numbers (values);
square_array (values);
print_square_root (values);

cout << "\n\n";

system("PAUSE");
return EXIT_SUCCESS;
}
{
int index;
cout << "Enter 8 numbers:\n";
for (index = 0; index < size; index++)
cin >> values [index];
}
void print_numbers (double values [size])
{
int index;
cout << "The numbers entered were:\n";
for (index = 0; index < size; index++)
cout << setw (9) << values [index];
cout << "\n\n";
}
void square_array (double values [size])
{
int index;

cout << "The squares of the numbers are:\n";
for (index = 0; index < size; index++)
{
values [index] = values [index] * values [index];
cout << "\n\n";
cout << showpoint << fixed << setprecision (2);
cout << setw (9) << values [index];
}
}
void print_square_root (double values [size])
{
int index;
cout << "The square root of the numbers are:\n";
for (index = 0; index < size; index++)
{

values [index] = sqrt (values [index]);
cout << "\n\n";
cout << showpoint << fixed << setprecision (2);
cout << setw (9) << values [index];
}

}``````

``#include <cmath>``