Reputation: 23
I have programmed a small program to find the cos of any number bur the result was all strange the cmd :
type the number 0.00
effincisy5
your cos =008C129E
Press any key to continue . . .
the code:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
float cos67 (float l,float j)
{
int k=0;
float sum=0,i=1;
while (k<=j)
{
sum +=i;
i*=(-l*l/((2*l)*(2*l-1)));
k+=1;
}
return sum;
}
int main(){
float l,j;
cout<<"type the number ";
cin>>l;
cout<<endl<<"effincisy" ;
cin>>j;
cout<<endl;
cos67(l,j);
cout<<"your cos ="<<cos67<<endl;
return 0;
}
so why the result have letters on the number?
or what does it mean?
Upvotes: 0
Views: 50
Reputation:
You are printing the address of the function and not the return value. Use:
cout<<"your cos ="<< cos67(l, j) <<endl;
Instead.
Upvotes: 3
Reputation:
This:
cout<<"your cos ="<<cos67<<endl;
is taking the address of the function and displaying it. You want the value the function returns:
cout<<"your cos ="<< cos67(l,j) <<endl;
Upvotes: 3