| | |
Trying To Find The Square Root Of Each Number Of A Array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 4
Reputation:
Solved Threads: 0
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"
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
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
•
•
Join Date: Apr 2005
Posts: 4
Reputation:
Solved Threads: 0
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 read_numbers (double numbers [SIZE]);
void print_numbers (double numbers [SIZE]);
void print_squares (double numbers [SIZE]);
void print_square_roots (double numbers [SIZE]);
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:
Code tags added. -Narue
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 read_numbers (double numbers [SIZE]);
void print_numbers (double numbers [SIZE]);
void print_squares (double numbers [SIZE]);
void print_square_roots (double numbers [SIZE]);
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:
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iostream> #include <iomanip> using namespace std; const int size = 8; void square_array (double values [size]); void read_numbers (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]; read_numbers (values); print_numbers (values); square_array (values); print_square_root (values); cout << "\n\n"; system("PAUSE"); return EXIT_SUCCESS; } void read_numbers (double values [size]) { 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]; } }
>along with the question that was asked of me to do
I couldn't care less what the question was. I already knew what your problem was, I just wanted to confirm it.
Add this:
That's where sqrt is declared.
I couldn't care less what the question was. I already knew what your problem was, I just wanted to confirm it.
Add this:
C++ Syntax (Toggle Plain Text)
#include <cmath>
I'm here to prove you wrong.
![]() |
Similar Threads
- Program that determines if a number is prime (C++)
- number of times each number in array occurs? (C)
- Is it possible to create a square root program without math.h (C++)
- find larget number in an array (C)
- C++ Square Root Problem (C++)
- help with square root finder (C++)
Other Threads in the C++ Forum
- Previous Thread: Inserting a control break in an array
- Next Thread: passing vector to a pointer?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






