ท่าน Admin ครับ ช่วยอันนี้หน่อยครับ

อยากให้อธิบายโปรแกรมภาษาปาสคาลที่ท่าน Admin เขียนให้หน่อยอ่ะครับ


โปรแกรม ตัดเกรดนักเรียน
--------------------

เงือ่นไขมีอยู่ว่า

คะแนน    0-49  เกรด  f
  50-59  เกรด  d
  60-69  เกรด  c
  70-79  เกรด  b
  80-100  เกรด  a

อื่นๆ Error

สามารถทำได้2แบบนะครัยโดยใช้ If และ case

แบบที่ 1 ใช้ IF


Program Cut_Grade;
uses crt;
var score:integer;
begin
    clrscr;
    write('Input Your Score = ');
    readln(score);
    if score>0 then
    begin
        if score<50 then
      begin
        writeln('Your Grade F');
      end
      else
        begin
            if score<60 then
            begin
            writeln('************');
            writeln('Your Grade D');
            end
            else
            begin
              if score<70 then
              begin
              writeln('************');
              writeln('Your Grade C');
              end
              else
              begin
                  if score<80 then
                  begin
                  writeln('************');
                  writeln('Your Grade B');
                  end
                  else
                  begin
                    if score<101 then
                    begin
                    writeln('************');
                    writeln('Your Grade A');
                    end
                    else
                    begin
                    writeln('***********');
                    writeln('Error Score');
                    end;
                  end;
              end;
            end;
        end;
        end
    else
    begin
      writeln('***********');
        writeln('Error Score');
    end;
    writeln;
    writeln;
    writeln('Press Any Key To Exit');
    readln;
end.

---------------------------------------
ชิ้นที่  2
โปรแกรมคำนวณ ภาษี และยอดเงินสุทธิ
------------------------------

ให้รับค่ารหัสประจำตัว ชื่อสกุล และ เงินเดือน

ถ้า เงินเดือนน้อยกว่า10000บาท  ไม่เสียภาษี
ถ้า เงินเดือน 10001-30000  เสียภาษี 3%
ถ้า เงินเดือน 30001-50000  5%
ถ้า เงินเดือน 50001 ขึ้นไป    7%

ภาษี=เงินเดือน*อันตราภาษี

เงินเดือน=เงินเดือน-ภาษี

ตัวแปรที่ใช้นะครับ

name ไว้รับชื่อ id ไว้รับรหัส salary:ไว้รับเงินเดือน กำหนดเป็น longint เพราะจำนวนเลขเยอะ tax ภาษี total เงินเดือนเมื่อหักภาษีแลว้

โปรแกรมนี้ไม่สามารถเขียนโดนใช้ case ได้นะครับ

เขียนโดยใช้ IF

program it4x;
uses crt;
var id,name:string;
    salary:longint;
    tax,total:real;
begin
    clrscr;
    write('What Is Your Id ? = ');
    readln(id);
    write('What Is Your Name ? = ');
    readln(name);
    write('Input Salary = ');
    readln(salary);
    clrscr;
    writeln('Your Id = ',id);
    writeln('Your Name = ',name);
    if salary<=10000 then
    begin
    writeln('Your Salary = ',salary)
    end
    else
    begin
    if salary<=30000 then
    begin
                      tax:=salary*3/100;
                      writeln('Your Tax 3% = ',tax:1:2);
                      total:=salary-tax;
                      writeln('Your Total Salary = ',total:1:2);
    end
    else
    begin
    if salary<=50000 then
    begin
                      tax:=salary*5/100;
                      writeln('Your Tax 5% = ',tax:1:2);
                      total:=salary-tax;
                      writeln('Your Total Salary = ',total:1:2);
    end
    else
        begin
                      tax:=salary*7/100;
                      writeln('Your Tax 7% = ',tax:1:2);
                      total:=salary-tax;
                      writeln('Your Total Salary = ',total:1:2);
        end;
        end;
        end;
        readln;
    end.

--------------------------

ชิ้นที่  3

โปรแกรมคำนวณว่า มีเงินเท่านี้ ได้ธนบัตร อะไรบ้าง กี่ใบๆ ประมาณนี้คับ

อันนี้ เป็นภาษา Pascal เลยนะครับ รันได้ ใช้แทนโค๊ดเทียมเลยก็ได้คับ


program it4x_thanabut;
uses crt;
var a,b,c,d,e,f,g,h,money:longint;
begin
    clrscr;
    write('Input Your Money := ');readln(money);
    repeat
    if money>=1000 then
    begin
          money := money-1000;
          a := a+1;
    end
    else
    if money>=500 then
    begin
          money := money-500;
          b := b+1;
    end
    else
    if money>=100 then
    begin
          money := money-100;
          c := c+1;
    end
    else
    if money>=50 then
    begin
          money := money-50;
          d := d+1;
    end
    else
    if money>=20 then
    begin
          money := money-20;
          e := e+1;
    end
    else
    if money>=10 then
    begin
          money := money-10;
          f := f+1;
    end
    else
    if money>=5 then
    begin
          money := money-5;
          g := g+1;
    end
    else
    if money>=1 then
    begin
          money := money-1;
          h := h+1;
    end;
    until money<=0;
    clrscr;
    writeln('Your 1000 := ',a);
    writeln('Your 500 := ',b);
    writeln('Your 100 := ',c);
    writeln('Your 50 := ',d);
    writeln('Your 20 := ',e);
    writeln('Your 10 := ',f);
    writeln('Your 5 := ',g);
    writeln('Your 1 := ',h);
    readln;
end.

------------------------------------------

ชิ้นที่  4 

โปรแกรม คำนวณ สี่เหลี่ยม สามเหลี่ยม วงกลม แบบเลือก Choice ใช้ Case นะครับ



program it4x;
uses crt;
var x,i,base,high:integer;
begin
    clrscr;
    writeln('Welcome To Program Calculator');
    writeln('-----------------------------');
    writeln('1.Rectangle');
    writeln('2.Circle');
    writeln('3.Triangle');
    writeln;
    write('Please Select Choice : ');
    readln(i);
    case i of
    1 :  begin
              clrscr;
              writeln('Program Rectangle');
              writeln('-----------------');
              writeln;
              write('Input Your High = ');readln(high);
              write('Input Your Base = ');readln(base);
              writeln('Area Of Rectangle is = ',high*base);
          end;
    2 : begin
              clrscr;
              writeln('Program Circle');
              writeln('--------------');
              writeln;
              write('Input Your Radius = ');readln(x);
              writeln('Area Of Circle is = ',3.14*x*x:1:2);
          end;
    3 : begin
              clrscr;
              writeln('Program Triangle');
              writeln('----------------');
              writeln;
              write('Input Your High = ');readln(high);
              write('Input Your Base = ');readln(base);
              writeln('Area Of Rectangle is = ',0.5*high*base:1:2);
          end;
    else
        begin
              clrscr;
              writeln('Your Unkwon Choice!!')
        end;
    end;
    writeln;
    write('Press Any Key To Exit');
    readln;
end.



ท่าน Admin ช่วยอธิบายทีละบรรทัดให้ผมทีนะครับ

ขอบคุณอย่างสูงเลยครับ
🏷️ หัวข้อที่เกี่ยวข้อง

💬 การตอบกลับ 2

#1
nooknickz
nooknickz
86 โพสต์
มั่ยชั่ย Admin อ่ะ ตอบได้ไหม รู้แค่อันเดียว

Program Cut_Grade; =โปรแกรมตัดเกรด

uses crt; = ชื่อยูนิต

var score:integer; = การกำหนดตัวแปรโดยใช่ชื่อ score โดยรับค่าเป็นตัวเลขจำนวนเต็ม

begin = คำสั่งเริ่มโปรแกรม

    clrscr; = การลบน่าจอแสดงผล

    write('Input Your Score = '); = แสดงคำว่า Input your score บนน่าจอ

    readln(score); = รับค่า score ผ่านคีบอร์ด

    if score>0 then = เงื่อนไขการแสดงเกรด ถ้า 0 -49 ได้เกรด F
    begin
        if score<50 then
      begin
        writeln('Your Grade F');
      end
      else
        begin
            if score<60 then เงื่อนไขการแสดงเกรด ถ้า 50 -59 ได้เกรด D
            begin
            writeln('************');
            writeln('Your Grade D');
            end
            else
            begin
              if score<70 then เงื่อนไขการแสดงเกรด ถ้า 60 -69 ได้เกรด C
              begin
              writeln('************');
              writeln('Your Grade C');
              end
              else
              begin
                  if score<80 then  เงื่อนไขการแสดงเกรด ถ้า 80 -100 ได้เกรด A
                  begin
                  writeln('************');
                  writeln('Your Grade B');
                  end
                  else
               



begin
                    if score<101 then
                    begin
                    writeln('************');
                    writeln('Your Grade A');
                    end
                    else
                    begin
                    writeln('***********');
                    writeln('Error Score');
                    end;
                  end;
              end;
            end;
        end;
    writeln;
    writeln;
    writeln('Press Any Key To Exit'); = คุณจะออกจากโปรแกรม
    readln;
end.  = จบโปรแกรมทั้งหมด
#2
Moshi
Moshi
16,996 โพสต์
ต้องขอบคุณ นุกนิ๊กมากเลยนะครับ ^^