# 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
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
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.
0
Commented:
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.
0
Commented:
This is the simplest code which I can offer.
{
In this program f is an integer variable which is used to format the
output. Formatting the output means much more than just allignment
of output. The expression :f:0 tells comuter(if f=13) to
reserve total length of 13 characters for number and 0 spaces for
numbers after decimal point. 0 because we know that cubes and squares of integers
are never in fractions. Try and see how different outputs come by
changing :f:0. If values of cubes and square grows larger simply
increase the value of f to format perfectly.

}
program square_cube;
uses crt;

var n,bigger_500,f : integer;
cube, square, sumcube, sumsquare : real;

begin
clrscr;
cube := 0; square := 0;
sumcube := 0; sumsquare := 0;
bigger_500 := 0; f := 13;
writeln('Number      Square        Cube');
for n := 1 to 15 do
begin
square := n * n;
cube := n * square;
sumsquare := sumsquare + square;
sumcube := sumcube + cube;
if cube > 500 then bigger_500 := bigger_500 + 1;
writeln(n:3,square:f:0,cube:f:0);
end;
writeln('--------------------------------');
writeln('Total',sumsquare:f-2:0,sumcube:f:0);

writeln;
if sumsquare > 2000 then writeln('The sum of squares is greater than 2000.')
else  writeln('The sum of squares is not greater then 2000.');

writeln('The number of cubes greater than 500 = ',bigger_500);
writeln;
writeln('Press ENTER to continue.....');
end.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
0
Author Commented:
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.
0
Commented:
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.
0
Author Commented:
I'm doing it in Turbo Pascal V7.0 for DOS.
0
Author Commented:
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!
0
Commented:
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.
0
Author Commented:
I just wasn't logged into the network. I feel sheepish!!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.