Advertisement
akevintg

Algorithm & Programming Assignment

Dec 9th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<ctype.h>
  3. #include<string.h>
  4. #include<Windows.h>
  5. int ascii(int length,char kata[50]){
  6.     system("cls");
  7.     int i;
  8.     int total=0;
  9.     int angka[8];
  10.     printf("Calculating .");
  11.     Sleep(1000);
  12.     printf(" . ");
  13.     Sleep(1000);
  14.     printf(" .\n ");
  15.     for(i=0; i<length; i++){
  16.         printf("%c", kata[i]);
  17.         total +=kata[i]-48;
  18.         angka[i]=kata[i]-48;
  19.         if(i%2==1)
  20.             printf(" ");
  21.         else printf("+");
  22.     }
  23.     Sleep(1000);
  24.     printf("\n%3.d+%-3.d %3.d+%-3.d",angka[0]+angka[1],angka[2]+angka[3],angka[4]+angka[5],angka[6]+angka[7]);
  25.     Sleep(500);
  26.     printf("\n%7.d+%-5.d",angka[0]+angka[1]+angka[2]+angka[3],angka[4]+angka[5]+angka[6]+angka[7]);
  27.     Sleep(200);
  28.     printf("\n= %d\n", total);
  29.     return total;
  30. }
  31. void check(char kata[50]){
  32.     system("cls");
  33.     int flag=0,length,i;
  34.      do{
  35.         flag = 1;
  36.         printf("Masukkan tanggal Lahir anda(Min Usia 22thn)\n(Format : ddmmyyyy): ");
  37.         scanf("%s", kata);fflush(stdin);
  38.         length = strlen(kata);
  39.         for(i=0; i<length; i++){
  40.             if(isalpha(kata[i])){
  41.                 flag = 0;
  42.                 break;
  43.             }
  44.         }
  45.         if(kata[0]-48>3||(kata[0]-48>=3&&kata[1]-48>1)){
  46.             printf("Hari yang anda masukan tidak valid\n");
  47.             flag=0;}
  48.         if(kata[2]-48>1||(kata[2]-48>=1&&kata[3]-48>2)){
  49.             printf("Bulan yang anda masukan tidak valid\n");
  50.             flag=0;}
  51.         if(kata[4]-48!=1||kata[5]-48!=9||(kata[6]-48==9&&kata[7]-48>1)){
  52.             printf("Tahun yang anda masukan tidak valid\n");
  53.             flag=0;}
  54.     }while(flag==0);
  55. }
  56. int spesial(int total){
  57.     printf("\n%d + %d =", (total-total%10)/10,total%10);
  58.     total=(total/10)%10+total%10;  
  59.     printf("\b\b = %d\n", total);
  60.     return total;
  61. }
  62. void result(int total){
  63.     int x=0;
  64.     system("cls");
  65.     do{
  66.         system("cls");
  67.         if(x<50)
  68.             printf("Running some analytical ");
  69.         if(x>=50)
  70.             printf("Preparing the result ");
  71.         printf("%d",x);
  72.         x++;
  73.     }while(x<=100);
  74.     system("cls");
  75.     printf("100%% Loading Complete\n");
  76.     printf("Based On your number (%d), you are ",total);
  77.     if (total==1)
  78.         printf("Leadership, lonely");
  79.     else if (total==2)
  80.         printf("Vocal, loving, emotional");
  81.     else if (total==3)
  82.         printf("Agresive, Impatient, Spritual");
  83.     else if (total==4)
  84.         printf("Inteligent, good planning, orderly");
  85.     else if (total==5)
  86.         printf("Protective, stubborn, good business");
  87.     else if (total==6)
  88.         printf("People & Family oriented, money");
  89.     else if (total==7)
  90.         printf("Lucky, lot of freedom, like to help people");
  91.     else if (total==8)
  92.         printf("Responsible, Stressful");
  93.     else if (total==9)
  94.         printf("Successful, greedy");
  95. }
  96. int main(){
  97.     char kata[50];
  98.     int total=0;
  99.     check(kata);
  100.     total=ascii(strlen(kata),kata);
  101.     while(total>=10)
  102.         total=spesial(total);
  103.     result(total);
  104.     getchar();
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement