Link to home
Start Free TrialLog in
Avatar of kazooie21
kazooie21

asked on

how you do a square and cubes table?

I need a program that will print a square and cubes table. It would like this:

Number    Square    Cube
     1          1      1

Once you get the square, couldn't you get the cube by multiplying the number *square? Or do you have to do a cube?
It should also print out the sum of the squares, the sum of the cubes, how many cubes were greater than 500, a message stating whether or not the sum of the squares exceeded 2,000.
Shouldn't it go something like this?

program SquareCubeTable;
var i, number, square, cube, sumsquare, sumcube: integer;

begin
   for i := 1 to 15 do
      begin
       square := i * i;
        cube:= number * square;
I don't know how to align it.  
     You would do the sum of the square and cubes like this?

begin
   sum:= 0;
   for i:= 1 to 15 do
   sum := i*i + i;
   writeln('sum of squares is ', sum)
      if sumsquares > 2,000 then
        writeln('Sum of squares was over 2,000 ')

begin
   sum:= 0;
    for I:= 1 to 15 do
     sum:= number * square + 1;
    writeln('sum of cubes is ', sum)

I don't how do this all in one program.
I wouldn' know about the greater than part
Avatar of kazooie21
kazooie21

ASKER

I hate when you try to post something in a table! It screws it all up! All the numbers in all three columns should be right-aligned.
Avatar of dbrunton
begin
  sumsquare := 0;
  sumcube := 0;
  cubesgreater := 0;
   for i := 1 to 15 do
    begin
      square := i * i;
      cube :=  i * square;
      sumsquare := sumquare + square;
      cubesquare := cubesquare + cube;
      if (cubesquare > 500) then
        inc(cubesgreater);
    end;
end.

This will do most of it for you.  You need to print out the statements and tidy the code up.

Note that you must initialise your values before you use them.
ASKER CERTIFIED SOLUTION
Avatar of sumant032199
sumant032199
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your assessment.
It works fine, but I can't get it to print.  In fact, the table and the payroll
programs won't print either. I've used the 'uses printer' command in all of them.
Are you doing this under Windows 95?

If so you may have told Windows 95 that you do not print MS-DOs programs and hence Windows won't let the Pascal program print.

Solution.  Save output to a text file and then retrieve the file into a wordprocessor program,  change font to Courier and print.
I'm doing it in Turbo Pascal V7.0 for DOS.
How do you do that in DOS? Everyone else has been able to print on their computer. I've tried 3 different computers and it still won't print!
You need code similar to the following

uses Printer;

Write(Lst, 'This is output');

This should work.  Try it and report back.  This is straight out of the TP 5.5 manual and assumes that your printer is connected to your parallel port LPT1.
I just wasn't logged into the network. I feel sheepish!!