Doesn't write out decimals...

#include <iostream>
#include <string>
using namespace std;

int main()
{
int h;
int min;
int sek;
cout << "Ange antalet timmar: ";
cin >> h;
cout << "Ange antalet minuter: ";
cin >> min;
cout << "Ange antalet sekunder: ";
cin >> sek;
double eTimmar;
double eMin;
double eSek;
eTimmar = h + min/60 + sek/3600;
eMin = h*60 + min + sek/60;
eSek = h*3600 + min*60 + sek;
cout << "Tidsomvandling ger:" << endl;
cout << eTimmar << "h = " << eMin << " min = " << eSek << " s" << endl;
system("pause");
return 0;
}

Why isn't this program writing out the decimals? I've set the type as "double",
so it should, right?
min and sek are integers, so min/60 and sek/3600 are integer divisions, so the result is also integer.
Simply do min/60.0, or double(min)/60.
@helios
min and sek are integers, so min/60 and sek/3600 are integer divisions, so the result is also integer.
Simply do min/60.0, or double(min)/60.
-----------------------------------------------------------------------------------------------
Thanks! It worked when I made the divisions "double(min)/60"
Topic archived. No new replies allowed.