954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

School assignment in pascal

i have to create a program for school. here is the question:

pizza contains 355 calories per slice. jogging burns off 240 calories per hour. write a program to calculate how long, in hours and minutes, you would have to jog to burn off the pizza that you eat:

this is how it has to look:

How many slices of pizza? 3
you will have to jog 4.44 hours

this is what i have so far:

PROGRAM PIZZA (INPUT, OUTPUT);

VAR
SLICES, HOURS, MINUTES, CALORIES :INTEGER;
JOG :REAL;

BEGIN
WRITE ('HOW MANY SLICES OF PIZZA? ');
READLN (SLICES);
CALORIES := 355;

heres where i dont know what the hell im doing.
please help :confused:

nikkisboricua
Light Poster
36 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

It's been too long since I did Pascal, but in pseudocode:

caloriesEaten = 355 * slices
hoursToJog = caloriesEaten / 240

But if you want hours and minutes, you could do this with integers:

totalMinutesToJog = caloriesEaten / (240 / 60)
hoursToJog = totalMinutesToJog / 60
totalMinutesToJog = totalMinutesToJog - (hoursToJog * 60)

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

i cant remember much of pascal either, put just be careful about your data types because some of the division may well return horrible numbers which should be in REAL format not INT. otherwise looks good. as i said i cant really remember whether / it just returns the highest non-decimal answer or not but i think it actually gives a more precise answer than that.
--------------------------------------------------------------------------
NEW - FREE pc support using your Instant Messenger
www.easy-help.tk

easy-helper
Newbie Poster
9 posts since Jan 2005
Reputation Points: 10
Solved Threads: 1
 
program pizza;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
   CaloriesPerSlice = 355;
   CaloriesBurnedPerHour = 240;
var
   CaloriesBurnedPerMinute : Double;
   Hours : Double;
   SlicesOfPizzaEaten : Integer;
   TotalCalories : Integer;
   TotalMinutesToJog : Double;
begin
   writeln;
   write( 'How many slices of pizza? ' );
   read( SlicesOfPizzaEaten );

   CaloriesBurnedPerMinute := CaloriesBurnedPerHour / 60.0;
   TotalCalories := SlicesOfPizzaEaten * CaloriesPerSlice;
   TotalMinutesToJog := TotalCalories / CaloriesBurnedPerMinute;

   Hours := Round( TotalMinutesToJog / 60.0 * 100.0 ) / 100.0;

   writeln;
   writeln( 'You need to jog for ' + FloatToStr( Hours ) + ' hours.' );
   writeln;
end.
Jackrabbit
Light Poster
31 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You