Advertisement
DrAungWinHtut

functions.c

Mar 9th, 2023
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. //fun declaration
  5. void area();
  6. void BMI();
  7. void  lucky();
  8. void  gold();
  9. int max(int i1, int i2);
  10. int main()
  11. {
  12.     int ans = 0;
  13.     do {
  14.         printf("menu\n");
  15.         printf("-------\n");
  16.         printf("1-area calculation\n");
  17.         printf("2-gold calculation\n");
  18.         printf("3-bmi calculation\n");
  19.         printf("4-lucky baydin\n");
  20.         printf("5-maximum number test\n");
  21.         printf("0-exit\n");
  22.         printf("Choose one please (0,1,2,3,4,5): ");
  23.         scanf_s("%d", &ans);
  24.         printf("\n\n");
  25.         switch (ans) {
  26.         case 0: exit(0); break;
  27.         case 1: area(); break;
  28.         case 2: gold();  break;
  29.         case 3: BMI(); break;
  30.         case 4: lucky(); break;
  31.         case 5:  int a = 0; int b = 0;
  32.             int c = 0;
  33.             printf("Please Enter First Integer: ");
  34.             scanf_s("%d", &a);
  35.             printf("Please Enter Second Integer: ");
  36.             scanf_s("%d", &b);
  37.             c = max(a, b);
  38.             printf("max number is %d\n", c);
  39.             break;
  40.  
  41.         }
  42.         printf("\n\n");
  43.     } while (ans != 0);
  44.    
  45.    
  46.     return 0;
  47. }
  48.  
  49. void area() //fun definition
  50. {
  51.     //Input storatge
  52.     float L = 0.0;
  53.     float W = 0.0;
  54.     //Output storage
  55.     float A = 0.0;
  56.  
  57.     printf("Please enter L: ");
  58.     scanf_s("%f", &L);
  59.  
  60.     printf("Please enter W: ");
  61.     scanf_s("%f", &W);
  62.  
  63.     A = L * W;
  64.  
  65.     printf("Area = %0.2f\n\n", A);
  66.    
  67. }
  68.  
  69. void BMI()
  70. {
  71.     float weight = 0.0;
  72.     float height = 0.0;
  73.     float BMI = 0.0;
  74.     float feet = 0.0;
  75.     float inches = 0.0;
  76.     int i = 0;
  77.  
  78.     printf("enter your weight in kg: ");
  79.     scanf_s("%f", &weight);
  80.  
  81.     weight = weight * 2.2;
  82.     printf("your weight is %f pounds\n", weight);
  83.  
  84.     printf("enter your height  (feet:) ");
  85.     scanf_s("%f", &feet);
  86.     printf("enter your height  (inches:) ");
  87.     scanf_s("%f", &inches);
  88.  
  89.     height = (feet * 12) + inches;
  90.     printf("your height in  (inches:) is %f inches\n", height);
  91.  
  92.     BMI = (weight / (height * height)) * 703; //w=lb, h=inches
  93.  
  94.     printf("Your BMI is %f \n", BMI);
  95.  
  96.     if (BMI < 18.5)
  97.     {
  98.         printf("you are underweight\n");
  99.     }
  100.     else if ((BMI >= 18.5) && (BMI < 24.9))
  101.     {
  102.         printf("you are normal\n");
  103.     }
  104.     else if ((BMI >= 24.9) && (BMI < 29.9))
  105.     {
  106.         printf("you are overweight\n");
  107.     }
  108.     else
  109.     {
  110.         printf("you are Obese\n");
  111.     }
  112.     printf("\n\n");
  113.  
  114.    
  115. }
  116.  
  117. void  gold()
  118. {
  119.     float kyat = 0.0;
  120.     float pae = 0.0;
  121.     float yway = 0.0;
  122.     float kyats = 0.0;
  123.     float price_per_kyat = 0.0;
  124.     float total_gold_price = 0.0;
  125.  
  126.     printf("Please enter price_per_kyat value : ");
  127.     scanf_s("%f", &price_per_kyat);
  128.  
  129.     printf("Please enter gold weight (kyat pae yway) : ");
  130.     scanf_s("%f %f %f", &kyat, &pae, &yway);
  131.  
  132.     kyats = kyat + pae / 16 + yway / 128;
  133.     total_gold_price = price_per_kyat * kyats;
  134.  
  135.     printf("Total gold weights is %f kyats and Total price is %f kyats \n\n", kyats, total_gold_price);
  136.  
  137.  
  138. }
  139.  
  140. void  lucky()
  141. {
  142.     int year = 0;
  143.     int month = 0;
  144.     int day = 0;
  145.  
  146.     int sum = 0;
  147.     int mod = 0;
  148.  
  149.     printf("Lucky Star\n");
  150.     printf("==========\n");
  151.  
  152.     for (int i = 0; i < 1; i++) //i++ -> i = i+1;
  153.     {
  154.         printf("Please enter birthday dd-mm-yyyy : ");
  155.         scanf_s("%d-%d-%d", &day, &month, &year);
  156.  
  157.         sum = year + month + day;
  158.         mod = sum % 3;
  159.         if (mod == 0)
  160.         {
  161.             printf("You are not LUCKY\n");
  162.         }
  163.         else if (mod == 1)
  164.         {
  165.             printf("You are NORMAL\n");
  166.         }
  167.         else if (mod == 2)
  168.         {
  169.             printf("You are  LUCKY\n");
  170.         }
  171.         else {
  172.             printf("Invalid data\n");
  173.         }
  174.     }
  175.  
  176.  
  177. }
  178.  
  179. int max(int i1, int i2)
  180. {
  181.     int bigger = 0;
  182.     if (i1 > i2)
  183.     {
  184.         bigger = i1;
  185.     }
  186.     else {
  187.         bigger = i2;
  188.     }
  189.     return bigger;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement