fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. float h;
  5. int ts, ds;
  6. int SRate = 10;
  7. int pay;
  8.  
  9. printf("กรอกจำนวนชั่วโมงที่ใช้: ");
  10. scanf("%f", &h);
  11.  
  12. printf("กรอกส่วนลด: ");
  13. scanf("%d", &ds);
  14.  
  15. // ปัดเศษชั่วโมง
  16. ts = (int)h;
  17. if (h - ts >= 0.5) {
  18. ts = ts + 1;
  19. }
  20.  
  21. // คำนวณเงินที่ต้องจ่าย
  22. pay = (ts * SRate) - ds;
  23.  
  24. printf("\nจำนวนชั่วโมงที่คิดเงิน = %d ชั่วโมง\n", ts);
  25. printf("เงินที่ต้องจ่าย = %d บาท\n", pay);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.04s 25556KB
stdin
Standard input is empty
stdout
#include <stdio.h>

int main() {
    float h;
    int ts, ds;
    int SRate = 10;
    int pay;

    printf("กรอกจำนวนชั่วโมงที่ใช้: ");
    scanf("%f", &h);

    printf("กรอกส่วนลด: ");
    scanf("%d", &ds);

    // ปัดเศษชั่วโมง
    ts = (int)h;
    if (h - ts >= 0.5) {
        ts = ts + 1;
    }

    // คำนวณเงินที่ต้องจ่าย
    pay = (ts * SRate) - ds;

    printf("\nจำนวนชั่วโมงที่คิดเงิน = %d ชั่วโมง\n", ts);
    printf("เงินที่ต้องจ่าย = %d บาท\n", pay);

    return 0;
}