dimanche 29 septembre 2019

cannot convert 'double' to 'double*' for argument '2' to 'double calculation(int, double*)'

i send the address of k and the function should receive by its initialized pointer and next i want to use the value of k and calculate but getting that error.

#include<iostream>
using namespace std;

double calculation(int n,double *k){
    //cout<<&k <<endl <<*k <<endl <<k;
    if(n==0)
        return 0;
    if(n==1)
    return *k;
    else
     return *k / (2*n-3)+calculation(n-1,*k);
}

int main(){
    int n;
    double k=10.00;
    cout<<"Battery amount: " <<endl;
    cin>>n;
    double distance_covered= calculation(n, &k);
    cout<<"The car has moved: " <<distance_covered;
}

Aucun commentaire:

Enregistrer un commentaire