#include <iostream>
#include <cmath>
using namespace std;
int cubeAndSquare( int, int *);
int main (void){
int number = 5, cube, square;
int *ptr;
ptr = □
cout<< "The original value of number is "<< number<<endl;
cube = cubeAndSquare(number, ptr);
cout <<"The square of number "<< number<<" is " << *ptr <<endl;
cout <<"The cube of number "<< number<< " is"<<cube<<endl;
return 0;}
int cubeAndSquare(int n, int *square) {
*square= n * n;
return n * n * n;}
You can use the std double sqrt(double n) function or the double pow (double,double).
In this last case cout<<double pow(4.0,0.5); would produce 2.0.
rgds & hth`s
/*
#include <iostream>
#include <cmath>
usingnamespace std;
int cubeAndSquare( int, int *);
int main (void){
int number = 5, cube, square;
int *ptr;
ptr = □
cout<< "The original value of number is "<< number<<endl;
cube = cubeAndSquare(number, ptr);
cout <<"The square of number "<< number<<" is " << *ptr <<endl;
cout <<"The cube of number "<< number<< " is"<<cube<<endl;
cout<<"The squareroot of number "<<sqrt(number)<<endl;
getchar();
return 0;}
int cubeAndSquare(int n, int *square) {
*square= n * n;
return n * n * n;}
/*
The original value of number is 5
The square of number 5 is 25
The cube of number 5 is125
The squareroot of number 2.23607 <---*/
Thanks for the help but I recieved this error on build:
line 14 c:\users\p\documents\visual studio 2008\projects\square root1\square root1\sqrt1.cpp(15) : error C2668: 'sqrt' : ambiguous call to overloaded function
sqrt() does not take an int as an argument, you need to change this to a double, or float.
getchar(); holds the console open at the end of execution but you should use std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); instead.
[Edit]
Also, you need to include <limits> for that code
how do i return the square root of cubeAndSquare with a reference call and the sqrt() function call
instead of calling the cubeAndSquare () function by name assign its return value to some declared variable.
e.g double x= void squareroot(int n, int * square)
On return x will contain the (double) type value which you want the square root of.
Now call the squareroot function on x.