Help ME about type data
Nov 28, 2013 at 3:05pm UTC
Please help me, im realy confused :D
my source can't be compile but, can run ?
every i compile,always show [warning] converting to 'int' from 'double'.
How to fix it ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#include<iostream>
using namespace std;
int main()
{
//Nama : Eko Purnomo Bayu Aji__Nim : 13090043__Kelas: 1B__Prodi: D4 Teknik Informatika
string nama;/**/ char gol;
long int gaji_pokok;
long int gaji_lembur=50000,lama_lembur;
cout<<" ==========================================================\n" ;
cout<<" :: DAFRAT PERHITUNGAN GAJI PEGAWAI ::\n" ;
cout<<" ==========================================================\n\n" ;
cout<<"Nama Pegawai : " ;getline(cin, nama);
cout<<"Golongan<1,2,3> : " ;fflush(stdin);cin>>gol;
cout<<"Lama Lembur : " ;cin>>lama_lembur;
cout<<"\n" ;
system("cls" );
cout<<"DAFRAT PERHITUNGAN GAJI PEGAWAI\n==========================================================\n\n" ;
cout<<"Nama Pegawai : " <<nama<<"\n" ;
cout<<"Golongan<1,2,3> : " <<gol<<"\n" ;
cout<<"\n" ;
//Penentuan Gaji_Pokok
if (gol == '1' )/**/ {gaji_pokok=800000;}
else if (gol == '2' )/**/ {gaji_pokok=1200000;}
else if (gol == '3' )/**/ {gaji_pokok=2500000;}
//-Penentuan Gaji_Pokok
//Rumus Perhitungan
long int total_gaji_lembur=gaji_lembur*lama_lembur;
long int gaji_kotor=total_gaji_lembur+gaji_pokok;
double pajak=0.025*gaji_kotor;
long int total_gaji_kotor=gaji_pokok+total_gaji_lembur;
double asuransi=0.05*total_gaji_kotor;
int gaji_bersih=total_gaji_kotor-(asuransi+pajak);
//-Rumus Perhitungan
cout<<"Gaji Pokok : Rp." <<gaji_pokok<<"\n" ;
cout<<"Lama Lembur : " <<lama_lembur<<" Jam\n" ;
cout<<"Total Gaji Lembur : Rp." <<total_gaji_lembur<<"\n" ;
cout<<"Gaji Kotor : Rp." <<gaji_kotor<<"\n" ;
cout<<"\n" ;
cout<<"POTONGAN \n" ;
cout<<"Pajak <2,5%> : Rp." <<pajak<<"\n" ;
cout<<"Asuransi <5%> : Rp." <<asuransi<<"\n" ;
cout<<"Gaji Bersih : Rp." <<gaji_bersih<<"\n" ;
system("PAUSE" );
//Credit
char ulang;
cout<<"Lihat Credit ? (Y/N) " ;cin>>ulang;
if (ulang == 'y' || ulang == 'Y' )
{
system("cls" );
cout<<"====================================================\n" ;
cout<<"|| Program created by: ||\n" ;
cout<<"|| Nama : Eko Purnomo Bayu Aji ||\n" ;
cout<<"|| Nim : 13090043 ||\n" ;
cout<<"|| Kelas: 1B ||\n" ;
cout<<"|| Prodi: D4-Teknik Informatika ||\n" ;
cout<<":::::::::::::::::::::::::::::::::::::::::::::::;::::\n" ;
system("PAUSE" );
}
else {return 0;}
}
Nov 28, 2013 at 3:08pm UTC
A warning is exactly that; a warning. It's not a compilation error and your code does compile. It's simply warning you that you're assigning double values to integer variables, which will lead to truncation.
Nov 28, 2013 at 3:10pm UTC
it means my source right,and no error in there ?
Last edited on Nov 28, 2013 at 3:13pm UTC
Nov 28, 2013 at 3:13pm UTC
Yes. In particular, this line:
int gaji_bersih=total_gaji_kotor-(asuransi+pajak);
You're assigning the result of an operation involving doubles to an integer. If you change gaji_bersih to a double, you should be fine.
Last edited on Nov 28, 2013 at 3:16pm UTC
Nov 28, 2013 at 3:23pm UTC
i cant change, if i use
int gaji_bersih=total_gaji_kotor-(asuransi+pajak);
will show Rp.1200000 (example show)
and if i use
double gaji_bersih=total_gaji_kotor-(asuransi+pajak);
will show Rp.12000e+006
Topic archived. No new replies allowed.