--Originally published at blog de Horacio
What to Do
You implement this function in your own program in a file quiz3.cpp.
You should make a main routine that asks the user for a number and then calls your functions to calculate the square and cube roots of that number and prints them out.
What should you do if the user enters a negative number?
Publish your code on your own blog today (during class time is best) and use the tag #Quiz03 so it shows up nicely in our tag cloud.
code:
#include <iostream>
#include <math.h>
using namespace std;
double square_root(double x){
double square_root= sqrt(x);
return square_root;
}
double cube_root(double x){
double cube_root= cbrt(x);
return cube_root;
}
int main(){
double x;
std::cout << “introduce un numero” << ‘\n’;
std::cin >> x;
if (x<0) {
std::cout << “error” << ‘\n’;
}else {
std::cout <<square_root(x)<< ‘\n’;
std::cout <<cube_root(x) << ‘\n’;
}
return 0.0;
};