Hey guys.

I am making a simple console canender program for an exercise from a book, and it is going ok so far but I am having trouble with the spacing of it.

I have made a simple function that creates on day block like a normal calender would have, and then in main called this 30 times to print the calender out. I tried using a nested for loop as I would with arrays to create the boxes acorss the screen but they seem to only appear down the side of the screen when I run it.

It is quite a simple problem I am sure of it, can you see what I am doing wrong?

#include <iostream>

// function prototypes
void printBlock ( int );

// main function - driver /////////////////////////////////////////////////////
//
int main ( void ) {
	for ( int i = 0; i < 1; i++ ) {
		for ( int j = 1; j <= 30; j++ ) {
			printBlock ( j );

			if ( j % 7 == 0 ) {
				std::cout << "\n";
			}
		}
		std::cout << std::endl;
	}

	std::cin.get();

	return 0;
}

// function to print a single block of the calender
void printBlock ( int x ) {
	for ( int i = 1; i <= 7; i++ ) {
		std::cout << "*";
	}

	std::cout << "\n";

	for ( int i = 1; i <= 7 -2; i++ ) {
		std::cout << "*";
		for ( int j = 1; j <= 7 -2; j++ ) {
			std::cout << " ";
		}
		std::cout << "*\n";
	}

	for ( int i = 1; i <= 7; i++ ) {
		std::cout << "*";
	}
}

What do you mean? Do you want the blocks to appear in lines, like that?:

******  ******  ******  ******  ******
*    *  *    *  *    *  *    *  *    * 
*    *  *    *  *    *  *    *  *    * 
******  ******  ******  ******  ******

If you do, you need to print multiple blocks drawing-lines before finished the line.

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.