jeron1 gave you the important part - the printf calls need to be changed. Here is the documentation of the function :
cplusplus.com : printf[
^]. Printf needs to have one format string followed by the various arguments. For you that would look like this :
printf("\n%s\t |\t %s\t %d", k1.idpegawai, k1.nama, k1.umur );
One thing I recommend is that you move your new line characters (the '
\n
') to the end of the lines so the cursor is always left at the start of a line. That would make printf call look like this :
printf("%s\t |\t %s\t %d\n", k1.idpegawai, k1.nama, k1.umur );
It is a minor thing but it will make things a bit easier in general.
Also, you should take advantage of a feature in c++ whereby structs are actually classes with all members public by default. For your program, this means you could add a constructor to your class and cut down the amount of code considerably. Here's how that could look :
struct kelompok
{
char idpegawai[5];
char nama[10];
int umur;
kelompok() {}
kelompok( const char * id, const char * n, int u )
{
strcpy( idpegawai, id );
strcpy( nama, n );
umur = u;
}
};
and then the code in your main function could look like this :
int main(void)
{
struct kelompok k1( "P001", "revan", 18 );
struct kelompok k2( "P002", "joo", 18 );
struct kelompok k3( "P003", "rev", 18 );
struct kelompok k4( "P004", "van", 19 );
One last suggestion - add a
print
method to your structure. Here is how its prototype would look in the class :
struct kelompok
{
void print()
{
printf("%s\t |\t %s\t %d\n", idpegawai, nama, umur );
}
};
here is how the revised main function could look with those changes :
int main(void)
{
struct kelompok k1( "P001", "revan", 18 );
struct kelompok k2( "P002", "joo", 18 );
struct kelompok k3( "P003", "rev", 18 );
struct kelompok k4( "P004", "van", 19 );
printf("idpegawai | nama | umur \n");
printf("================================\n");
k1.print();
k2.print();
k3.print();
k4.print();
printf("================================\n");
return 0;
}