Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #define MAKS 10
- int kab (int);
- int error (int, int);
- void harikah (char *, char *, int);
- struct date {
- int tgl, bln, thn;
- char hari[MAKS];
- };
- int bl, bln[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
- main() {
- struct date today;
- struct date tom;
- int n, cektgl, cekbln;
- puts("=============== PROYEK AKHIR ===============\n");
- input:
- printf("Masukkan hari : "); gets(today.hari);
- printf("Masukkan tanggal : "); scanf("%d", &today.tgl);
- printf("Masukkan bulan : "); scanf("%d", &today.bln);
- printf("Masukkan tahun : "); scanf("%d", &today.thn);
- printf("Masukkan jangka hari : "); scanf("%d", &n);
- fflush(stdin);
- // proses penyalinan value
- bl = today.bln;
- tom.tgl = today.tgl+n;
- tom.bln = today.bln;
- tom.thn = today.thn;
- strcpy(tom.hari,today.hari);
- // pengecekan kabisat
- if(kab(today.thn))
- bln[2] = 29;
- // error checking
- harikah(today.hari,tom.hari,n);
- cektgl = error(today.tgl,1);
- cekbln = error(today.bln,2);
- if(cektgl || cekbln || tom.hari[0] == '0') {
- puts("--------------------------------------------");
- printf("Data yang Anda masukkan salah, ulangi lagi\n");
- //if(
- puts("--------------------------------------------");
- goto input;
- }
- // proses penentuan tanggal
- while(tom.tgl > bln[tom.bln]) {
- tom.tgl -= bln[tom.bln];
- tom.bln += 1;
- if(tom.bln > 12) {
- tom.bln = 1;
- tom.thn += 1;
- }
- }
- // output
- puts("--------------------------------------------");
- printf("Hari ini : \nHari : %s\n", today.hari);
- printf("Tanggal : %d\n", today.tgl);
- printf("Bulan : %d\n", today.bln);
- printf("Tahun : %d\n", today.thn);
- puts("--------------------------------------------");
- printf("%d Hari lagi : \nHari : %s\n", n,tom.hari);
- printf("Tanggal : %d\n", tom.tgl);
- printf("Bulan : %d\n", tom.bln);
- printf("Tahun : %d\n\n", tom.thn);
- return 0;
- }
- int kab (int x) {
- int a;
- if(x % 400 == 0)
- a = 1;
- else if(x % 100 == 0)
- a = 0;
- else if(x % 4 == 0)
- a = 1;
- else
- a = 0;
- return (a);
- }
- int error (int y,int z) {
- int re;
- switch(z) {
- case 1 : if((y < 1) || (y > bln[bl])) {
- re = 1;
- }
- case 2 : if((y < 1) || (y > 12)) {
- re = 1;
- }
- default : re = 0;
- }
- return (re);
- }
- void harikah (char *h, char *k, int n) {
- int a, i, cek;
- char *hari[] = {"0","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu","Ahad"};
- for(i=0;i<8;i++) {
- cek = strcmpi(h,hari[i]);
- if(cek == 0) {
- a = i;
- break;
- }
- }
- if(cek != 0)
- strcpy(k,hari[0]);
- else {
- a += n;
- while(a > 7) {
- a -= 7;
- }
- strcpy(k,hari[a]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement