help please - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help please

stuart1512stuart1512 Posts: 3Member
[color=Red]Your assignment will be to produce a program, structure chart and testing plan for a program that does the following:

Take two strings from the user:
-The first will be the current date in DD/MM/YYYY format
-The second will be the current time HH:MM

The program will then output the following:
-How many days there are left in the month
-How many months left in the year
-How many years left before the year 3000
-Working out what fraction of the day is left (Remembering there are 24 hours in a day, and 12:00 would be 0.5 through the day)[/color]

[b]here is the code i have at the moment, im just a bit stuck at trying to do the bitwhere it does the days left of the month, how many months are left, and the left from year 3000 bit.[/b]




[italic]program Assignment2;

Uses
crt;

Var
Date:String;
Day,Month,Year,DaysLeft,MonthsLeft:String;
Hours,Minutes:String;

begin

Writeln ('Please enter the current date in the format DD/MM/YYYY');
Readln;
Writeln ('Please enter the current time in the format (24 hour) HH:MM');
Readln;

Day:= Copy(Date,1,2);
Month:= Copy(Date,4,5);
Year:= Copy(Date,7..10);
Hours:= Copy(Time,1,2);
Minutes:= Copy(Time,4,5);

If Month = 01,03,05,07,08,10,12 then
Days = 31
End If

If Month = 04,06,09,11 then
Days = 30
End If

If Month = 02 then
Days = 28
End If

end.[/italic]

[b]thanks in advance[/b]

Comments

  • AtexAtex Posts: 268Member
    Well, it looks like you mixing Pascal with Basic here [code]If Month = 01,03,05,07,08,10,12 then
    Days = 31
    [red]End If[/red][/code]so you should go through some Pascal tutorials to get the basics first...
    Back to your assignment, you'll need to find out if the current year is a leap year or not:[code][color=Blue]function is_leap_year(year:word):boolean; { returns true if the given year is a leap year}
    begin
    is_leap_year:=(year mod 4=0) and not((year mod 100=0) and (year mod 400<>0));
    end;[/color][/code]Then adjust the number of days in February accordingly:[code][color=Blue]const days_in_month:array[1..12] of byte=(31,28,31,30,31,30,31,31,30,31,30,31);

    if is_leap_year([red][/red]) then inc(days_in_month[2]);[/color][/code]Next you'll only need to do some subtractions to see how many days are left in the respective month, months in year and years till 3000. To calculate the fraction of the day, first find out how many hours and minutes are left then convert the minutes to fractions ( e.g. 30 min = 0.5 h ) using the following formula[code]minute_fractions:=minutes/60;[/code]Add the fractions to the remaining hours then apply this formula[code]fraction_of_the_day_left:=24/hours_left;[/code]Hope this helps...
Sign In or Register to comment.