my first code

assalamu’alaikum warahmatullahi wabarakatuh…

wah lama ga update ya, maklumlah sibuk garap revisi, nonton gundam, mikir masa depan dll. o iya, kemarin ‘ditantang’ teman (asli teman karena dia sudah tunangan) untuk “code war” membuat program yang bisa menghitung nilai entalpi pembakaran hidrokarbon. berikut adalah listing program entalpi versi 0.0.1. masih kotor kodenya dan cuma bisa untuk menghitung alkena dengan satu ikatan rangkapūüė¶

 

#include <stdio.h>
#include <stdlib.h>

/* program untuk menghitung nilai entalpi pembakaran alkana, alkena dan alkuna */
/* version 0.0.1 still bad coded, no function !!! */

int main (void)

{

const int CC = 345;
const int CH = 415;
const int CC_DOUBLE = 615;
const int CC_TRIPLE = 837;
const int OH = 460;
const int CO = 750;
const int OO = 495;

/* main program */

int n;
// int m = 1;
char SELECT;
char q;
double  ECC;
double  ECH;
double  EOH;
double  ECO;
double  EOO;
double  H;

printf(“\n\n\n\nPROGRAM MENGHITUNG ENTALPI PEMBAKARAN ALKANA DAN ALKENA !!!!”);
printf(“\n\n\nONLY WORKS WITH 1 DOUBLE BOND AND TRIPLE BOND !!!”);

// USER MEMILIH PERHITUNGAN ALKANA ATAU  ALKENA

// JIKA USER MEMILIH a MAKA ALKANA,  b  MAKA ALKENA, c MAKA ALKUNA

printf(“\n\n\nKetikkan ‘a’ untuk menghitung entalpi pembakaran alkana, ‘b’ alkena¬† dan ‘c’¬† untuk alkuna :¬† “);
scanf(“%s”, &SELECT);

// Define CASE¬† “a” ALKANA !!!!

switch(SELECT)

{

case ‘a’ :

printf(“\n\n\n\nmasukkan jumlah atom C : “);
scanf(“%d”,&n);

/* do computation */

ECC = ( n – 1 ) * CC;
EOO = (( 3 * n + 1)/ 2) *OO;
ECO = 2 * n* CO;
EOH = (2 * n + 2) *OH;
ECH = (2 * n + 2) *CH;

H = ECC + ECH + EOO – ECO – EOH;

/* print the result */

printf(“ECC = %f\n”, ECC);
printf(“EOO = %f\n”, EOO);
printf(“ECO = %f\n”, ECO);
printf(“EOH = %f\n”, EOH);
printf(“ECH = %f\n”, ECH);
printf(“n = %d\n”,n);
printf(“\nentalpi pembakaran : %f\n “, H);

break;

// define case ‘b’ ALKENA !!!!

case ‘b’ :

// more complex features…working with any double bonds
// if double bonds > 1 then CH = CH – 2 * n – m
// nilai m valid jika nilai n > 3
// nilai mMAX = n

// jika nilai n =  1 maka ketik ulang

while ( n = 1)

{

printf(“\n\n\n\nmasukkan jumlah atom C : “);
scanf(“%d”,&n);

while ( n > 1)

{

// do computation

ECC = ( n – 2 ) * CC;
EOO = (( 3 * n )/ 2) *OO;
ECO = 2 * n* CO;
EOH = (2 * n ) *OH;
ECH = (2 * n ) *CH;

H = CC_DOUBLE + ECC + ECH + EOO – ECO – EOH;

// print the result

printf(“ECC = %f\n”, ECC);
printf(“EOO = %f\n”, EOO);
printf(“ECO = %f\n”, ECO);
printf(“EOH = %f\n”, EOH);
printf(“ECH = %f\n”, ECH);
printf(“n = %d\n”,n);
printf(“\nentalpi pembakaran : %f\n “, H);

// exit the loop

printf(“\n\nketik ‘q’ untuk keluar dari program “);
scanf(“%s”,&q);
exit(EXIT_SUCCESS);

break;

}

}

// define case ‘c’ ALKUNA!!!!

case ‘c’ :

// jika n = 1  maka ketik ulang

while ( n = 1)

{

printf(“\n\n\n\nmasukkan jumlah atom C : “);
scanf(“%d”,&n);

while ( n > 1)

{

// do computation

ECC = ( n – 2 ) * CC;
EOO = (( 2 * n – 1)) *OO;
ECO = 2 * n* CO;
EOH = (2 * (n – 1)) *OH;
ECH = (2 * n Р2  ) *CH;

H = CC_TRIPLE + ECC + ECH + EOO – ECO – EOH;

// print the result

printf(“ECC = %f\n”, ECC);
printf(“EOO = %f\n”, EOO);
printf(“ECO = %f\n”, ECO);
printf(“EOH = %f\n”, EOH);
printf(“ECH = %f\n”, ECH);
printf(“n = %d\n”,n);
printf(“\nentalpi pembakaran : %f\n “, H);

// exit the loop

printf(“\n\nketik ‘q’ untuk keluar dari program “);
scanf(“%s”,&q);
exit(EXIT_SUCCESS);

break;

}

}

}

return 0;

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s