IT4X เทคนิคคอมพิวเตอร์ โน๊ตบุค ข่าว IT

ข่าวสาร / ความรู้ => คนเขียนโปรแกรม => ข้อความที่เริ่มโดย: Robo_kub ที่ กุมภาพันธ์ 15, 2010, 17:06:32

หัวข้อ: admin ดูโปรแกรมให้ผมหน่อยคับ ขอบคุนมากคับ
เริ่มหัวข้อโดย: Robo_kub ที่ กุมภาพันธ์ 15, 2010, 17:06:32
ผมลองทำแล้วแต่ไม่ประสบคาวมสำเร็จอ่ะ คับ

ลองยกตัวอย่างโปรแกรมด้วย ก้อ ดีนะคับ

ขอบคุณมากๆๆๆคับ
หัวข้อ: Re: งั้นขอ วิธี การเขียนคำสั่ง case ซ้อน case แล้วกันนะคับ
เริ่มหัวข้อโดย: Moshi ที่ กุมภาพันธ์ 15, 2010, 17:32:54
ไม่ต้องตั้งกระทู้ใหม่เร่ื่อยๆ ก็ได้นะครับ กระทู้เดิมผมก็ไปตอบ

คนใหม่ที่มาดูเค้าจะงง ละก็ตั้งกันมั่วซั่ว

http://www.it4x.com/forum/index.php?topic=1138.15 (http://www.it4x.com/forum/index.php?topic=1138.15)

เนี่ยครับ หน้านี้ก็มีโปรแกรมเป็นเมนู

จากนั้นตรงโค๊ด

'1' : writeln('1');
'2' : writeln('2');
'3' : writeln('3');

ก็เปลี่ยนเป็น writeln('1'); เป็น Begin กับ end; แล้วก็ละเลงโปรแกรมเลยครับ
หัวข้อ: Re: งั้นขอ วิธี การเขียนคำสั่ง case ซ้อน case แล้วกันนะคับ
เริ่มหัวข้อโดย: Robo_kub ที่ กุมภาพันธ์ 15, 2010, 18:38:56
ขอโทดแบบรู้สึกผิดสุดุคับ
หัวข้อ: Re: งั้นขอ วิธี การเขียนคำสั่ง case ซ้อน case แล้วกันนะคับ
เริ่มหัวข้อโดย: Robo_kub ที่ กุมภาพันธ์ 16, 2010, 19:52:02
พี่คับ ผมเอาไปทำดูแล้ว  แต่มัน คอมไพล์ ไม่ได้อ่ะคับ

ไม่รู้ว่ามันผิดตรงไหน  (โปรแกรมอันนี้ ยังไม่เสร็จนะคับ ยังต้องเขียนอีกเยอะ)

อันที่จริงผมก้ออยู่ ปวช. เหมือนกันนะคับ

program test01;
uses    crt;
var     num:byte;
        chr,ans:char;
        a,b:real;
begin
     repeat
     clrscr;
     textcolor(red);
     writeln ('welcom to my program');
     writeln;
     textcolor(yellow);
     writeln ('please select manu');
     writeln;
     textcolor(blue);
     writeln('1.manu temperature');
     textcolor(green);
     writeln('2.manu money');
     textcolor(red);
     writeln('3.manu triangle');
     textcolor(blue);
     writeln('4.manu year');
     textcolor(red);
     writeln('5.manu left year');
     textcolor(blue);
     writeln('6.game');
     writeln;
     write('enter your choice:');
     readln(num);
     writeln;
     case num of
     1:begin
            write('select tump c ro f');
            readln(chr);
            case chr of
                 'C','c' : begin
                           write('temp in c');
                           read(a);
                           b:=a*9/5+32;
                           writeln('temp in faren',b:2:2);
                           end;
                 'F','f' : begin
                           write('temp in c');
                           read(a);
                           a:=b*9/5+32;
                           writeln('temp in faren',a:2:2);
                           end;
            end;
   

     write('continue Y or N');
     ans:=readkey;
     ans:=upcase(ans);
     until ans='N';
     readln;
     end;
end.

อันนี้แค่ทดสอบเฉยๆนะคับ ย้ำ แค่ทดสอบเฉยๆคับ

อย่าหัวเราะเยอะนะคับ
หัวข้อ: Re: admin ดูโปรแกรมให้ผมหน่อยคับ ขอบคุนมากคับ
เริ่มหัวข้อโดย: Moshi ที่ กุมภาพันธ์ 17, 2010, 09:08:33
แก้ให้แล้วนะครับ ดูเอานะว่าผิดตรงไหน

program test01;
uses    crt;
var     num:integer;
        chr,ans:char;
        a,b:real;
begin
     repeat
     clrscr;
     textcolor(red);
     writeln ('welcom to my program');
     writeln;
     textcolor(yellow);
     writeln ('please select manu');
     writeln;
     textcolor(blue);
     writeln('1.manu temperature');
     textcolor(green);
     writeln('2.manu money');
     textcolor(red);
     writeln('3.manu triangle');
     textcolor(blue);
     writeln('4.manu year');
     textcolor(red);
     writeln('5.manu left year');
     textcolor(blue);
     writeln('6.game');
     writeln;
     write('enter your choice: ');
     readln(num);
     clrscr;

   case num of
           1 : begin
                         write('select tump c ro f : ');
                   readln(chr);
                   case chr of
                     'C','c' : begin
                               write('temp in c :');
                                 readln(a);
                                 b:=a*9/5+32;
                                 writeln('temp in faren',b:2:2);
                                   end;
          'F','f' : begin
                                 write('temp in c : ');
                                 readln(a);
                                 a:=b*9/5+32;
                                 writeln('temp in faren',a:2:2);
                                 end;
end;
                    end;
        end;


     write('continue Y or N');
     ans:=readkey;
     ans:=upcase(ans);
     until ans='N';
end.
หัวข้อ: Re: admin ดูโปรแกรมให้ผมหน่อยคับ ขอบคุนมากคับ
เริ่มหัวข้อโดย: Robo_kub ที่ กุมภาพันธ์ 17, 2010, 20:08:47
ขอบคุนคับ