Sunday, April 15, 2012

Contoh Kode Program Menggunakan Fungsi Dan Perulangan


  1. #include<stdio.h>
  2. #include<conio.h>
  3. menu();
  4. goreng();
  5. uduk();
  6. kuning();
  7. rames();
  8. kucing();
  9. kebuli();
  10. main()
  11. {
  12. int a;
  13. while(a!=7)
  14. {
  15. menu();
  16. scanf("%d",&a);
  17. switch(a)
  18. {
  19. case 1: {
  20. clrscr();
  21. goreng();
  22. break;
  23. }
  24. case 2: {
  25. clrscr();
  26. uduk();
  27. break;
  28. }
  29. case 3:
  30. {
  31. clrscr();
  32. rames();
  33. break;
  34. }
  35. case 4:
  36. {
  37. clrscr();
  38. kuning();
  39. break;
  40. }
  41. case 5:
  42. {
  43. clrscr();
  44. kucing();
  45. break;
  46. }
  47. case 6:
  48. {
  49. clrscr();
  50. kebuli();
  51. break;
  52. }

  53. case 7:{ printf("keluar");}
  54. }
  55. }
  56. }
  57. menu()
  58. {
  59. clrscr();
  60. printf("\nWARUNG MAKAN LANGSUNG KENYANG\n");
  61. printf("-----------------------------\n");
  62. printf("1. Nasi Goreng\n");
  63. printf("2. Nasi Uduk\n");
  64. printf("3. Nasi Rames\n");
  65. printf("4. Nasi Kuning\n");
  66. printf("5. Nasi Kucing\n");
  67. printf("6. Nasi Kebuli\n");
  68. printf("7. Keluar\n");
  69. printf("-----------------------------\n");
  70. printf("Pilih [1-7]: ");
  71. }
  72. goreng()
  73. {
  74. printf("\nHarganya Rp.100.000,00");
  75. getch();
  76. }
  77. uduk()
  78. {
  79. printf("\nHarganya Rp.500.000,00");
  80. getch();
  81. }
  82. rames()
  83. {
  84. printf("\nHarganya Rp.200.000,00");
  85. getch();
  86. }
  87. kucing()
  88. {
  89. printf("\nHarganya Rp.400.000,00");
  90. getch();
  91. }
  92. kuning()
  93. {
  94. printf("\nHarganya Rp.300.000,00");
  95. getch();
  96. }
  97. kebuli()
  98. {
  99. printf("\nHarganya Rp.500.000,00");
  100. getch();
  101. }


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.