fork download
  1.  
  2. #include <stdio.h>
  3.  
  4. int main() {
  5. const float rate_per_hour = 50 ;
  6. const int total_users = 10;
  7. float hours,discount,net,cost;
  8. int i;
  9. for (i=1; i<=total_users; i++ ){
  10. printf ("กรอกจำนวนชั่งโมงการใช้งานของคนที่%d:", i );
  11. scanf ("%f", &hours) ;
  12. //คำนวณเงินก่อนลด
  13. cost = hours*rate_per_hour;
  14. // คำนวณส่วนลด
  15. if(hours >= 5 ){
  16. discount = cost * 0.05; //ลด5%
  17. } else{
  18. discount = cost * 0.03; //ลด3%
  19. }
  20. // ค่าบริการสุทธิ
  21. net = cost - discount ;
  22.  
  23. // แสดงผล
  24.  
  25. printf("ผู้ใช้คนที่%d:\n",i);
  26. printf("ชั่วโมงที่ใช้งาน = %.2f บาท\n",hours);
  27. printf(" ค่าบริการก่อนลด =%.2f บาท\n ", cost);
  28. printf(" ส่วนลด =%.2f บาท\n ", discount);
  29. printf(" ค่าบริการสุทธิ =%.2f บาท\n\n ", net);
  30.  
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.02s 25876KB
stdin
Standard input is empty
stdout
#include <stdio.h>

int main() {
    const float rate_per_hour = 50 ;
    const int total_users = 10;
  float hours,discount,net,cost;
    int i;
    for (i=1; i<=total_users; i++ ){
        printf ("กรอกจำนวนชั่งโมงการใช้งานของคนที่%d:", i );
        scanf ("%f", &hours) ;
        //คำนวณเงินก่อนลด
        cost = hours*rate_per_hour;
        // คำนวณส่วนลด
        if(hours >= 5 ){
            discount = cost * 0.05;   //ลด5%
        } else{
            discount = cost * 0.03; //ลด3%
        }
        // ค่าบริการสุทธิ
        net = cost - discount ;

        // แสดงผล

        printf("ผู้ใช้คนที่%d:\n",i);
        printf("ชั่วโมงที่ใช้งาน = %.2f บาท\n",hours);
         printf(" ค่าบริการก่อนลด =%.2f บาท\n  ", cost);
           printf(" ส่วนลด =%.2f บาท\n  ", discount);
            printf(" ค่าบริการสุทธิ =%.2f บาท\n\n  ",   net);
        
    }

    return 0;
}