Hello All...

To be honest, this is a bit overwhelming, but I'm hoping that someone might be able to steer me in the right direction. I am currently taking a correspondence course in Computer Programming, and without instructional support, am finding that the material can be somewhat overwhelming.

I'm looking to find someone who has taken a similar course, preferably from Stratford Career Institute, and who might be able to assist me with some questions I have.

Thanks all for reading my post.

Terry

Recommended Answers

All 6 Replies

You are more likely to get your questions answered if you actually post them.

The problem I have been given is to write a program that calculates the squares and the cubes of the numbers from 0 to 10 and uses tabs to print out the table. The part where I'm getting hung up is that I am only allowed to use the if statement.

I wrote the following code to show me what the output should be, however the keyword in the question is to "write a program that CALCULATES..."

/* Calculate the squares and cubes of the numbers from 0 to 10 */
/* using tabs to separate the columns */

#include "stdafx.h"
#include <stdio.h>

int main ( void )
{
/* Not proper code - Simply shows what output should look like  */

	printf( "number\tsquare\tcube\n" );
	printf( "0\t0\t0\n" );
	printf( "1\t1\t1\n" );
	printf( "2\t4\t8\n" );
	printf( "3\t9\t27\n" );
	printf( "4\t16\t64\n" );
	printf( "5\t25\t125\n" );
	printf( "6\t36\t216\n" );
	printf( "7\t49\t343\n" );
	printf( "8\t64\t512\n" );
	printf( "9\t81\t729\n" );
	printf( "10\t100\t1000\n\n" );
	
	return 0;
}

This doesn't sounds right - if statement - are you sure its not the for statement?

I've double checked the statements I was introduced to in this particular chapter, and basically it's the if statement that was being emphasized. I have checked all of the coding examples in the chapter, and the for statement was not introduced.

I do appreciate your help with this problem.

I state this because, here's the code using a for statement

#include <stdio.h>

#define TABLE_SIZE 10

int main(int argc, char**argv)
{
	unsigned int i = 0;
	fputs("num#\tsqr#\tcude#\n", stdout);

	for (i = 0; i <= TABLE_SIZE; ++i)
		fprintf(stdout, "%u\t%u\t%u\n", i, i * i, i * i * i);
	return 0;
}

I really can't envision a neat solution with an if statement...

Maybe the idea was to simply explicitly print the answers, and getting the data columns, lined up.

There is no choice needed, so no if statement is necessary, imo.

Standard practice would be to use a loop to print this table up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.