int and double,c++

Hello!I am trying to make a programm at c++ which will read grads and will give degs.The only problem i have is that when i give an integer as grad,the programm doesn't return to me the right numbers as sec.it always returns 0 or 60 or something else with "e".i think the problem is that grads are declared as double,but i can't understand why.

the programm is this:

// ba8moi se moires
#include <iostream>
using namespace std;

void grads2deg(double grads,double &deg,double &min,double &sec)
{
double moires, lepta;
moires=180*grads/200;
deg=(int)moires;
lepta=(moires-deg)*60;
min=(int)lepta;
sec=(lepta-min)*60;
}

int main()
{
double x_grads, x_deg, x_min, x_sec;

cout<<"enter grad ";
cin>>x_grads;

grads2deg(x_grads, x_deg, x_min, x_sec);

cout<<"degs are "<<x_deg<<" degs, "<<x_min<<" mins and "<<x_sec<<" secs.";
return 0;
}

i whould be gratefull if anyone could help me...
closed account (zvRX92yv)
Please enclose the code inside [code][/code] tags.
Or else, we won't help you.

And please read - http://www.cplusplus.com/articles/Ny86b7Xj/
Last edited on
I don't see any pointers here, Nahiyan. I see C++-style references, but not pointers.
EDIT: Nahiyan edited his post. Yes, please read that article for future posts, pel k.

Try adding .0s to all the numbers in your grads2deg function. This was C++ will know for sure that you meant to make them doubles.

-Albatross
Last edited on
i have already tried that but it had no effect.thanks,anyway...i also read this site but i couldn't understand what bothered you that much,Nahiyan.it whould help me if you could tell me in order not to make the same mistakes again...

[// ba8moi se moires
#include <iostream>
using namespace std;

void grads2deg(double grads,double &deg,double &min,double &sec)
{
double moires, lepta;
moires=180*grads/200;
deg=(int)moires;
lepta=(moires-deg)*60;
min=(int)lepta;
sec=(lepta-min)*60;
}

int main()
{
double x_grads, x_deg, x_min, x_sec;

cout<<"enter grad ";
cin>>x_grads;

grads2deg(x_grads, x_deg, x_min, x_sec);

cout<<"degs are "<<x_deg<<" degs, "<<x_min<<" mins and "<<x_sec<<" secs.";
return 0;
}]
is that what you mean about code?sorry about your time but i am new and the site above helped me,but not as i much as i would like to...
@pel k

When I inputted 89.3 grads, my output was 80 degs, 22 mins and 12 secs., while 89.7 came out as 80 degs, 43 mins and 48 secs. Seems to be working okay, I think.
the problem was when i was inputed ints,like 54 grads.i found the answer,though,and the correct programm is

// Programming Techniques
// ba8moi se moires
#include <iostream>
#include <iomanip>
using namespace std;

void grads2deg(double grads,int &deg,int &min,double &sec)
{
double moires, lepta;
moires=0.9*grads;
deg=(int)moires;
lepta=(moires-deg)*60.;
min=(int)lepta;
sec=(lepta-min)*60.;
}

int main()
{
double x_grads, x_sec;
int x_deg, x_min;
cout<<"Enter angle in grad :";
cin>>x_grads;

grads2deg(x_grads, x_deg, x_min, x_sec);

cout<<fixed<<setprecision(3)<<endl;
cout<<"Angle is "<<x_deg<<" deg, "<<x_min<<" min, "<<x_sec<<" sec"<<endl;

system("pause");
return 0;
}

Anyway,thanks a lot anyone tried to help me!
Topic archived. No new replies allowed.