Hi, I am trying by best to code this program which takes user input of ten different numbers and displays it's square and cube, from the below code I can display the square of input numbers but in cube i am having problem please help me solving this.

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>  
       
  
      using namespace std;
      const int size = 10;
      const int size1 = 10;
      void square_array (int values [size]);
      void read_numbers (int values [size]);
      void cube_array (int values [size1]);
      int main(int argc, char *argv[])
{
      const int size = 10;
      const int size1 = 10;
       int values [size];
       int i [size];
       int a [size1];
       read_numbers (values);
       square_array (values);
       cube_array (values);
        
cout << "\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}
void read_numbers (int values [size])
     {
int index;
    cout << "Enter 10 numbers:\n";
    for (index = 0; index < size; index++)
    cin >> values [index];
    }
void square_array (int values [size])
     {
  
int index;
    cout << "\nThe square of your input numbers are:\n";
    for (index = 0; index < size; index++)
    {
    values [index] = values [index] * values [index];
    cout << "\n\n";
    cout << "Square is ---> " << values [index];
        }
      }
  void cube_array ( int values [size1])
        {
        int index;
        cout << "\n\nThe cube root of the numbers are:\n";
        for (index = 0; index < size1; index++)
        {
          values [index] = values [index] * values [index];
        cout << "\n\n";
        cout << values [index];
}
  
      }

]

Edited 7 Years Ago by Nick Evan: Add code-tags

1> use code tag

2> in function square_array() and cube_array() u are modifying the original array loosing the original values.

Good eye, dkalita.

In other words, OP, you need to either only display the values (save to an int and output that int) or, if you want to keep all the squared and cubed values, you'll need to store them in square_array and cube_array.

Edited 7 Years Ago by donaldw: n/a

For your cube array do your calculation like this :

for(int i = 0; i < Size; i++){
values[i] = values[i] * sqrt( float(values[i]) );
}

That way you multiply your square number by its root, which is the
original number you inputed.

This article has been dead for over six months. Start a new discussion instead.