ข่าว IT ล่าสุด
ถูกใจอย่าลืม Like Fanpage
ช่วยดูทีครับ ผู้มีความรู้ทั้งหลาย
แสดงแล้ว 5146 ครั้ง /
มกราคม 28, 2010, 23:12:57

freedom008

ออฟไลน์
กระทู้ : 11
คะแนนขอบคุณ : 0
คือ อ. สั่งงานมาให้ผมทำแต่ผมอ่านแล้ว  ลองแล้วก็ทำไม่ได้ (ผมไม่เข้าใจ*-*)

Program demo6_4;
uses crt;
var  c : byte;
     s,t : real;
     na : string[30];
const line='====================================';
begin
     clrscr;
     Writeln(' *** Report Tax ***');
     Writeln(line);
     Write('Code='); readln(c);
     Write('Name='); readln(na);
     Write('Salary'); readln(s);
     If s > 50000 then t :=s*10/100
     Else if s >= 40000 then t:=s*8/100
     Else if s >= 30000 then t:=s*6/100
     Else if s >= 20000 then t:=s*4/100
     Else if s >= 10000 then t:=s*2/100
     Else t :=s*0/100;
     Write('Tax :=',t:10:2);
     Writeln(line);

 End.

โจทร์  จากโปรแกรมนี้ จงเขียนขึ้นใหม่โดยใช้คำสั่ง case แทนคำสั้ง if

(ผมว่าผมพิมโปรแกรมถูกแล้วแต่มันก็รันแล้วตอบไม่ไป  กรุณาช่วยผมทีครับ)

   


Moshi

ออฟไลน์
กระทู้ : 16,996
คะแนนขอบคุณ : 45
it4x สังคมแห่งการเรียนรู้
มกราคม 29, 2010, 07:16:35
Program it4x;
uses crt;
var  c : byte;
     s : longint;
     t : real;
     na : string[30];
const line='====================================';
begin
     clrscr;
     Writeln(' *** Report Tax ***');
     Writeln(line);
     Write('Code='); readln(c);
     Write('Name='); readln(na);
     Write('Salary'); readln(s);
     case s of
     0..9999 : t :=s*0/100;
     10000..19999: t :=s*2/100;
     20000..29999: t :=s*4/100;
     30000..32000: t :=s*6/100;
     else
     t :=8*2/100;end;
     Writeln('Tax :=',t:1:2);
     Writeln(line);
     readln;
end.

freedom008

ออฟไลน์
กระทู้ : 11
คะแนนขอบคุณ : 0
มกราคม 30, 2010, 18:21:13
ขอคุณมากๆเลยครับ *-*  และวันนี้ ก็มีมาีอีกข้อ ต้องขอรบกวนอีกละครับ

Program sem6_13;
Uses crt;
Var  height,base,redius,width,length,side,area:real;
     ans:char;

Begin
     clrscr;
     writeln('Menu selection for calculate the area');
     writeln;
     writeln('1.Triangle.');
     writeln('2.Circle.');
     writeln('3.Rectangln.');
     writeln('4.Square.');
     write('Select =====>'); ans:=readkey;
     writeln;
     case ans of
          '1':begin
                   write('base ='); readln(base);
                   write('height ='); readln(height);
                   area:=0.5*base*height;
                   writeln('Area of triangle =',area:6:2);
              end;


           '2':begin
                    write('radius ='); readln(redius);
                    area:=pi*redius*redius;
                    writeln('Area of circle +',area:6:2);
               end;


           '3':begin
                    write('width ='); readln(width);
                    write('length ='); readln(length);
                    area:=length*width;
                    writeln('Area of rectangle =',area:6:2);
               end;


           '4':begin
                    write('side of square ='); readln(side);
               area:=side*side;
               writeln('Area of square =',area:6:2);
               end;
            end;{Case}
            writeln(#07);
            readln;
End.


อันนี้เป็นข้อสอบก่อนเรียน -*- โจทร์มีอยู่ว่า  
  ให้พัฒนาโปรนี้อันนี้ให้ ดียิ่งขึ้น คือ เวลา ที่โปรแกรมมันให้เราเลือก กด 1 2 3 4 ถ้าเรากดเลือก 1 2 3 4  ก็จะเลือกได้ แต่ถ้าเรากดนอกเหนือจากนั้นโปรแกรมมันจะ ไม่ทำงานและเด้ง
   ผมจึงคิดว่าจะพัฒนาโปรแกรมนี้โดย หาก ผู้เลือก เลือกกดนอกเหนือจาก 1 2 3 4  โปรแกรมจะขึ้น คำว่า "Please select. 1 2 3 4 only"
 แต่ปัญหาอยู่ที่ว่า ผมยังไม่ได้เรียน แล้วเขียนไม่เป็น จึงต้องรบกวนท่านๆ และพี่ แอดมินด้วยครับ
« แก้ไขครั้งสุดท้าย: มกราคม 30, 2010, 18:24:59 โดย freedom008 »

Moshi

ออฟไลน์
กระทู้ : 16,996
คะแนนขอบคุณ : 45
it4x สังคมแห่งการเรียนรู้
มกราคม 30, 2010, 20:55:03
Program sem6_13;
Uses crt;
Var  height,base,redius,width,length,side,area:real;
     ans:char;

Begin
     clrscr;
     writeln('Menu selection for calculate the area');
     writeln;
     writeln('1.Triangle.');
     writeln('2.Circle.');
     writeln('3.Rectangln.');
     writeln('4.Square.');
     write('Select =====>'); ans:=readkey;
     writeln;
     case ans of
          '1':begin
                   write('base ='); readln(base);
                   write('height ='); readln(height);
                   area:=0.5*base*height;
                   writeln('Area of triangle =',area:6:2);
              end;


           '2':begin
                    write('radius ='); readln(redius);
                    area:=pi*redius*redius;
                    writeln('Area of circle +',area:6:2);
               end;


           '3':begin
                    write('width ='); readln(width);
                    write('length ='); readln(length);
                    area:=length*width;
                    writeln('Area of rectangle =',area:6:2);
               end;
           '4':begin
                    write('side of square ='); readln(side);
               area:=side*side;
               writeln('Area of square =',area:6:2);
               end;
           else
           writeln('Please select. 1 2 3 4 only');
            end;{Case}
            writeln(#07);
            readln;
End.

freedom008

ออฟไลน์
กระทู้ : 11
คะแนนขอบคุณ : 0
มกราคม 30, 2010, 21:15:27
ขอบคุณมากๆครับ แต่  เวลาผู้เลือก เลือกนอกจาก 1 2 3 4 แล้ว มันขึ้น('Please select. 1 2 3 4 only') ก็จริง
แต่มันจะกลับไปทำงานไม่ได้อะครับ ผมอยากให้ขึ้น  ('Please select. 1 2 3 4 only')  แล้วกลัว ไปทำงานที่เลือก 1 2 3 4
อีกครั้งอะครับ ต้องใช้คำสั้ง label  และ goto ใช่ไหมครับ ท่านแอดมิน ลองทำให้ดูหน่อยครับ ผมยังไม่ได้เรียน  label  กับ goto
                                                                                       ขอบคุณครับ

Moshi

ออฟไลน์
กระทู้ : 16,996
คะแนนขอบคุณ : 45
it4x สังคมแห่งการเรียนรู้
มกราคม 30, 2010, 22:07:11
Program sem6_13;
Uses crt;
Var  height,base,redius,width,length,side,area:real;
     ans:char;

Begin
     clrscr;
     writeln('Menu selection for calculate the area');
     writeln;
     writeln('1.Triangle.');
     writeln('2.Circle.');
     writeln('3.Rectangln.');
     writeln('4.Square.');
     write('Select =====>'); ans:=readkey;
     writeln;
repeat
     case ans of
          '1':begin
                   write('base ='); readln(base);
                   write('height ='); readln(height);
                   area:=0.5*base*height;
                   writeln('Area of triangle =',area:6:2);
              end;


           '2':begin
                    write('radius ='); readln(redius);
                    area:=pi*redius*redius;
                    writeln('Area of circle +',area:6:2);
               end;


           '3':begin
                    write('width ='); readln(width);
                    write('length ='); readln(length);
                    area:=length*width;
                    writeln('Area of rectangle =',area:6:2);
               end;
           '4':begin
                    write('side of square ='); readln(side);
               area:=side*side;
               writeln('Area of square =',area:6:2);
               end;
           else
           writeln('Please select. 1 2 3 4 only');
            end;{Case}
until ans = '1','2','3','4';
            writeln(#07);
            readln;
End.

ถ้ามัน ERROR ยังไงก็ลองแก้ๆดูเอานะครับ พอดีช่วงนี้งานยุ่งมาก

freedom008

ออฟไลน์
กระทู้ : 11
คะแนนขอบคุณ : 0
มกราคม 31, 2010, 09:36:45
ท่าน แอทมินครับ มัน  ERROR ตรง ; ซื่งผมก็ไม่รู้จะแก้ยังไงครับ ลง งมๆ เปลี่ยนดูแล้วก็ไม่ไดครับ สงสัยจะเป็นตรงคำสั้งใหม่ที่แอดมีนเขียงลงอะครับ   ถ้าท่าน แอดมีนว่างก็ดูให้ผมทีนะครับ เดียวผมจะลองงมต่อดูครับ   ขอบคุณครับ

Moshi

ออฟไลน์
กระทู้ : 16,996
คะแนนขอบคุณ : 45
it4x สังคมแห่งการเรียนรู้
มกราคม 31, 2010, 11:21:39
ท่าน แอทมินครับ มัน  ERROR ตรง ; ซื่งผมก็ไม่รู้จะแก้ยังไงครับ ลง งมๆ เปลี่ยนดูแล้วก็ไม่ไดครับ สงสัยจะเป็นตรงคำสั้งใหม่ที่แอดมีนเขียงลงอะครับ   ถ้าท่าน แอดมีนว่างก็ดูให้ผมทีนะครับ เดียวผมจะลองงมต่อดูครับ   ขอบคุณครับ

เอา end; หลัง case ลบทิ้งมั้งคับ

freedom008

ออฟไลน์
กระทู้ : 11
คะแนนขอบคุณ : 0
มกราคม 31, 2010, 12:47:05
ก็ยังไม่ได้อ่ะครับ มันน่าจะเป็น ตรงนี้ until ans = '1','2','3','4'; มันฟ้องว่า ; ตรงแถวนี้อ่ะครับ

Moshi

ออฟไลน์
กระทู้ : 16,996
คะแนนขอบคุณ : 45
it4x สังคมแห่งการเรียนรู้
มกราคม 31, 2010, 13:41:20
Program it4x;
Uses crt;
Var  height,base,redius,width,length,side,area:real;
     ans:char;

Begin

     clrscr;
     repeat
     writeln('Menu selection for calculate the area');
     writeln;
     writeln('1.Triangle.');
     writeln('2.Circle.');
     writeln('3.Rectangln.');
     writeln('4.Square.');
     write('Select =====>'); ans:=readkey;
     writeln;
     case ans of
          '1':begin
                   write('base ='); readln(base);
                   write('height ='); readln(height);
                   area:=0.5*base*height;
                   writeln('Area of triangle =',area:6:2);
              end;


           '2':begin
                    write('radius ='); readln(redius);
                    area:=pi*redius*redius;
                    writeln('Area of circle +',area:6:2);
               end;


           '3':begin
                    write('width ='); readln(width);
                    write('length ='); readln(length);
                    area:=length*width;
                    writeln('Area of rectangle =',area:6:2);
               end;
           '4':begin
                    write('side of square ='); readln(side);
               area:=side*side;
               writeln('Area of square =',area:6:2);
               end;
           else
           begin
           clrscr;
           writeln('Please select. 1 2 3 4 only');end;
            end;{Case}
until (ans = '1') or (ans = '2') or (ans = '3') or (ans = '4');
            writeln(#07);
            readln;
End.

freedom008

ออฟไลน์
กระทู้ : 11
คะแนนขอบคุณ : 0
มกราคม 31, 2010, 15:52:28
ขอบคุณมากกกกครับ

 

ด้วยฟังค์ชั่น ตอบด่วน คุณสามารถใช้โค๊ดและ เครื่องหมายแสดงอารมณ์ได้ เหมือนการตั้งกระทู้ธรรมดา แต่สามารถทำได้สะดวกกว่า

ระวัง: หัวข้อนี้ไม่มีการอัพเดทมานานถึง 120 วัน

แจ้งเตือน: โพสของคุณจะไม่แสดงจนกว่าผู้ดูแลจะอนุมัติ.
ชื่อ: อีเมล์: