help please

[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;




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

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


[b]thanks in advance[/b]


  • 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}
    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.

Howdy, Stranger!

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


In this Discussion