help~urgent ~pascal

2007-03-28 3:19 am
plz try yr best~
Write a Pascal program to display the Chinese Astrology. The user should input a year of birth within this century ( i.e. from 1900 up to 2100 )

Sample output 1 :
What is your year of birth ? 1999
Your birthday is in the year of Rabbit.

Sample output 2 :
What is your year of birth ? 1983
Your birthday is in the year of Boar.

Sample output 3 :
What is your year of birth ? 2345
Out of range !

do i need to type all the years()1900-2100)???(is the any other ways?)

回答 (2)

2007-03-28 4:18 am
✔ 最佳答案
哦..你可以用array黎set variable ga~

Var
year : array[1900 .. 2100] : integer;

下面果d可以用mod,,再同if then check..

write('What is your year of birth ?');
readln(year);
If year<2100 or year>1900 then
Begin
year := year mod 12
if year = 1 then writeln('Your birthday is in the year of Chicken.');
if year = 2 then writeln('Your birthday is in the year of Dog.');
if year = 3 then writeln('Your birthday is in the year of Pig.');
.
.
.
if year = 7 then writeln('Your birthday is in the year of Rabbit.');
.
.
.
if year = 12 then writeln('Your birthday is in the year of Monkey.');

end;
else writeln('Out of range !');


個program類似咁樣,,
我個pascal壞左,,check唔到,,
唔知岩唔岩,,sor...
其他你應該識la...
參考: 自己
2007-03-28 4:43 am
上面的思路基本正確, 但做法有d 錯, 首先係唔駛用Array, 而且學到呢做題, 應該未學到Array, 下面是正確的程式:
var
year:integer;
begin
Write('What is your year of birth ?');
readln(year);
if (year>=1900) and (year<=2100) then
case year mod 12 of
4:writeln('Your birthday is in the year of Rat.');
5:writeln('Your birthday is in the year of Ox.');
6:writeln('Your birthday is in the year of Tiger.');
7:writeln('Your birthday is in the year of Rabbit.');
8:writeln('Your birthday is in the year of Dragon.');
9:writeln('Your birthday is in the year of Snake.');
10:writeln('Your birthday is in the year of Horse.');
11:writeln('Your birthday is in the year of Sheep.');
0:writeln('Your birthday is in the year of Monkey.');
1:writeln('Your birthday is in the year of Chicken.');
2:writeln('Your birthday is in the year of Dog.');
3:writeln('Your birthday is in the year of Boar.');
end
else
writeln('Out of range !');
Readln;
end.

如果未學過case...的話, 可以改用12個if
即係
if year mod 12=4 then writeln('Your birthday is in the year of Rat.');
連續12個。

唔駛由1900--2100全部一個個地試, 因為佢地每12年重複一次, 例如1900係鼠, 咁1912,1924,1936,1948,1960...都係鼠年, 而佢地除以12的餘數都同樣係4, 所以只要判斷餘數就ok, 其他亦如此類推, 所以只要判斷除以12的餘數分別為0--11就可以知道該年的生肖。

2007-03-30 21:45:07 補充:
你點入我的名, 可以email向我發問。
參考: 多年程式設計經驗


收錄日期: 2021-04-12 21:11:40
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070327000051KK03337

檢視 Wayback Machine 備份