dx/dy2

- Hello, im making a calculator that uses no cmath library, please help me, im supposed to have power,square root, fmin, and fmax, im confused about the fmin,fmax, and square root. Not sure how the math goes for them, but im currently on the square root




#include <iostream>

#include <string>
using namespace std;



int power(int number, int raise)
{
int result = number;
for(int i = 0; i < raise; i++)
result = result * number;
return result;
}


double squareRoot (double number) {
double temp;
double x0;
x0 = 3 * (10*10);

for (int i = 1; i < 3; i++) {
temp = 0.5(x0 + (number/x0));
}

return temp;
}



int main()
{
char response;
int number;
int power;
int a;
int b;

cout << "Please enter a number: " << endl;
cin >> number;

cout << "The square root of " << number << "is: " << squareroot(number, 2) << endl; // i would return the function where it says "squareroot(number, 2)".

cout << "Please enter the power of the number you would like to raise the number too: " << endl;
cin >> power;
cout << number << " raised to the power of " << power << " is: " << power(number, raise) << endl;

cin >> response;
return 0;
}
Last edited on
I didn't understand, can you explain me better what do you need? (in a simple language)
yes okay
Overview:
In this program you will be recreating the previous simple math program. However, rather than using the functions: sqrt, pow, fmin, and fmax from the <cmath> library, you will be creating your own functions. Your function names will be:
SquareRoot: //This function should be able to calculate the square root of any number. See hint below.
Power : //This function should be able to calculate any exponent greater than or equal to 0. It does not need to calculate fractional power. This is extremely difficult to do.
Minimum: //This function should be able to take in two numbers and return the smaller of the two numbers.
Maximum: //This function should be able to take in two numbers and return the larger of the two numbers.

Hint:
In this function you are going to have to use a for loop. Remember the the syntax for a for loop is: for(initialize; check; increment/decrement) When you check, you need to check and see if whether i is less than the exponent the user passed into the function.
i don't did the square root, is very difficult... But the other functions:

#include <iostream>
using namespace std;

void power(){

cout << "POWER:\n";

int exp, pow, base;

cout << "Put the base: ";
cin >> base;

cout << "Put the exponent: ";
cin >> exp;

pow = base;

for(int i = 1; i < exp; i++){
pow *= base;
}

cout << "The result is: "<< pow<<endl;

}

void smaller(){

cout << "SMALLER NUMBER:\n";

int x, y;

cout << "Put the number one: ";
cin >> x;

cout << "Put the number two: ";
cin >> y;

if(x < y){
cout << x << " is smaller than " << y<<endl;
}
else if(x == y){
cout << x << " is equal to " << y<<endl;
}
else{
cout << y << " is smaller than " << x<<endl;
}

}

void larger(){

cout << "LARGER NUMBER:\n";

int x, y;

cout << "Put the number one: ";
cin >> x;

cout << "Put the number two: ";
cin >> y;

if(x > y){
cout << x << " is larger than " << y<<endl;
}
else if(x == y){
cout << x << " is equal to " << y<<endl;
}
else{
cout << y << " is larger than " << x<<endl;
}

}

int main(){

power();
smaller();
larger();

return 0;

}

do you need that?
Last edited on
YES THANK YOU SO MUCH! just need to edit it, ill turn it in for less credit for not having the sqrt but thats fine!
Hahahah, nice.
And... Can i ask you something? do you have windows, mac or linux? if you have mac can you see this pls? because i don't understand how to do it... :/
http://www.cplusplus.com/forum/general/190079/
i tried three days to install the library but i can't!! D':
Topic archived. No new replies allowed.