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:

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)

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

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.
This article has been dead for over six months. Start a new discussion instead.