I am trying to create a program that allows me to find the nth root of a number. I tried running this on xcode and, I get an error that prevents me from running it. I'm getting an error for this line:
double f(double x) {
In this line, I am trying to declare a function, but it seems I'm declaring it incorrectly. xcode says expected ;
. How can I address this issue?
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <stdio.h>
#include <ctype.h>
#include "helloworld.h"
#include <locale>
using namespace std;
double newton( int n, int number);
string lowercase (string word);
int main()
{
int n;
int number;
cout << "This program can find the nth root of a number without actually solving the problem" <<endl;
cout << "Tell me what the value of n is: ";
cin >> n;
cout << "What is the number that you want to get rooted";
cin >> number;
newton(n, number);
}
double newton( int n, int number) {
const double epsilon = .0001;
double x0;
double x1 = number;
double f(double x) {
return (double) pow(x, n) - number;
}
double der_f(double x) {
return (double) n*pow(x, n-1);
}
while( abs(x1-x0) < epsilon) {
x0 = x1;
x1 = x0 -f(x0)/der_f(x0);
}
return x1;
}