แบบฝึกหัดตัวอย่าง PASCAL อยากให้เขียนโปรแกรมอะไรเป็นตัวอย่างขอได้นะครับ
ขอได้ที่ PM ในเว็ปนะครับ PM หา Admin เลยครับผม
แล้วเดียวผมจะเอามาลงให้ครับผม
🏷️ หัวข้อที่เกี่ยวข้อง
📤 แชร์บทความนี้
💬 การตอบกลับ 68
Moshi
16,996 โพสต์
— วาสนา link=topic=1138.msg32622#msg32622 date=1361370285
พี่คะ คำสั่งนี้หนูลองเอามารันแล้ว มันผิดตรงไหนคะ พี่ช่วยหน่อยนะค่ะ
program teat1;
uses Crt;
var baht,donller,euro,yen,money:integer;
begin
Clrscr;
writeln('inset you money=');
writeln('1.donller');
writeln('2.euro');
writeln('3.yen');
writeln;
case money of
'1donller':begin
write('baht='); readln(baht);
write('donller='); readln(donller);
money: 30*donller*baht=;
writeln('money donller=')
end;
'2euro' :begin
write('baht='); readln(baht);
write('euro='); readln(euro);
money: 50*euro*baht=;
writeln('money euro=')
end;
'3yen' :begin
write('baht='); readln(baht);
write('yen='); readln(yen);
money 40*yen*baht=;
end;
readln;
End.
พี่ดูคร่าวๆนะครับ
ยังไม่รับค่าตัวแปร money เลยครับ
แล้วส่วน money ประกาศด้านบนเป็น int ในเงื่อนไข เช็คเป็น string ต้องใช้ 1,2,3,4 เป็นตัวเลขจำนวนเต็มครับ
jojojoy bj
4 โพสต์
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.
____________________________________________
ถ้าเรา อยากเปลี่ยน จาก คำสั่ง CASE เป็น while เรา ต้องเลี่ยนแปลงเพิ่มเติม ตรงไหน บ้างค่ะ แร้ว ก็ เพิ่ม ให้ผู้ใช้ กด 1 ถ้าต้องการทำงานต่อ กด 0 ต้องการหยุดทำงาน.............ลอง เปลี่ยนหลายครังแระ แต่ ทำไม่ได้สักที รบกวนหน่อย นะค่ะ ........ขอบคุณ มากๆๆๆๆๆ ล่วงหน้า ค่ะ ขอบคุณ ค่ะ
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.
____________________________________________
ถ้าเรา อยากเปลี่ยน จาก คำสั่ง CASE เป็น while เรา ต้องเลี่ยนแปลงเพิ่มเติม ตรงไหน บ้างค่ะ แร้ว ก็ เพิ่ม ให้ผู้ใช้ กด 1 ถ้าต้องการทำงานต่อ กด 0 ต้องการหยุดทำงาน.............ลอง เปลี่ยนหลายครังแระ แต่ ทำไม่ได้สักที รบกวนหน่อย นะค่ะ ........ขอบคุณ มากๆๆๆๆๆ ล่วงหน้า ค่ะ ขอบคุณ ค่ะ
✏️ แก้ไขล่าสุด: 3 มีนาคม 2556
Moshi
16,996 โพสต์
— jojojoy bj link=topic=1138.msg32665#msg32665 date=1361687463
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.
____________________________________________
ถ้าเรา อยากเปลี่ยน จาก คำสั่ง CASE เป็น while เรา ต้องเลี่ยนแปลงเพิ่มเติม ตรงไหน บ้างค่ะ แร้ว ก็ เพิ่ม ให้ผู้ใช้ กด 1 ถ้าต้องการทำงานต่อ กด 0 ต้องการหยุดทำงาน.............ลอง เปลี่ยนหลายครังแระ แต่ ทำไม่ได้สักที รบกวนหน่อย นะค่ะ ........ขอบคุณ มากๆๆๆๆๆ ล่วงหน้า ค่ะ ขอบคุณ ค่ะ
while เป็น loop นะครับ
เพราะฉะนั้น จะใช้ while แทน case เป็นไปไม่ได้แน่นอนครับ ยกเว้นแต่จะเอา while ครอบให้มันวนซ้ำการทำงานเรื่อยๆ ได้ครับ
program it4x;
uses crt;
var x,i,base,high:integer,keyx:integer;
while keyx=1 do
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 1 To Continue');
readln(keyx);
end;
อันนี้เป็นโค๊ดคร่าวๆครับ ลองไปดัดแปลงแก้ไขดูครับ หมายเหตุ* ยังไม่ได้ลองรันครับ อาจมี error ได้ แค่ให้แนวคิดครับ
jojojoy bj
4 โพสต์
ค่ะ ขอบคุณ น๊ คร๊......แต่ลองรันดูแร้ว ติด ตรง while นิดนึง ......จะลองแก้ ดูค่ะ
ขอบคุณ นะ ค่ะ ::) ???
ขอบคุณ นะ ค่ะ ::) ???
jojojoy bj
4 โพสต์
รบกวน อีก ข้อ นะ ค่ะ :P :P :P
รับค่าคะแนน ยืยยันค่าคะแนนที่รับ ตรวจสอบเกรดที่ได้รับ ใช้คำสั่ง while
____________________________
enter score 79
you entered 79 correct? (y/n):n
Enter score again 97
this time you entered 97 correct? (y/n) : y
you grade : A
:-X 8) ??? :-* :-* :-*
รบกวนหน่อย นะค่ะ คุณ moshi ขอบคุณคร้าาาาาาา
รับค่าคะแนน ยืยยันค่าคะแนนที่รับ ตรวจสอบเกรดที่ได้รับ ใช้คำสั่ง while
____________________________
enter score 79
you entered 79 correct? (y/n):n
Enter score again 97
this time you entered 97 correct? (y/n) : y
you grade : A
:-X 8) ??? :-* :-* :-*
รบกวนหน่อย นะค่ะ คุณ moshi ขอบคุณคร้าาาาาาา
Moshi
16,996 โพสต์
— jojojoy bj link=topic=1138.msg32671#msg32671 date=1361705325
รบกวน อีก ข้อ นะ ค่ะ :P :P :P
รับค่าคะแนน ยืยยันค่าคะแนนที่รับ ตรวจสอบเกรดที่ได้รับ ใช้คำสั่ง while
____________________________
enter score 79
you entered 79 correct? (y/n):n
Enter score again 97
this time you entered 97 correct? (y/n) : y
you grade : A
:-X 8) ??? :-* :-* :-*
รบกวนหน่อย นะค่ะ คุณ moshi ขอบคุณคร้าาาาาาา
น่าจะประมาณนี้ครับ
write('Enter Score = ');
readln(score);
while x != 1 do
begin
write('you ebtered ',score,' correct? (y/n) = ');
readln(check);
if check='y' then
begin
x = 1
end
else
begin
write('Enter Score again = ');
readln(score);
x = 2
end
end
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;
ไม่ได้ลองรันจริงนะครับ ไม่ได้เขียน Pascal นานแล้วไม่มีโปรแกรม ลองๆแนวนี้ครับ ตรงสีแดงๆอาจมีเออเร่อลองไล่แก้ดูอีกทีครับ
jojojoy bj
4 โพสต์
ขอบคุณ นะค่ะ :) :) มาช้าไปหน่อย มัวอ่านหนังสือ ยุ๊ ไม่ได้เปิดคอม เรยยย
ขอบคุณ คร๊าฟฟฟฟฟฟฟฟฟ ::) ::) ::) ::)
ขอบคุณ คร๊าฟฟฟฟฟฟฟฟฟ ::) ::) ::) ::)
Moshi
16,996 โพสต์
:) แวะมาเยี่ยมเว็บบ่อยๆนะครับ