Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-21-2005, 04:37 PM   #1 (permalink)
C++noob
Registered User
 
Join Date: Mar 2005
Posts: 4
C++noob is on a distinguished road
Help with a simple program

Hi guys, Im taking an intro to programming course, because I've always been good at working with computers, unfortunatley I suck!!!! at programming, and thus I suck at this course.

I need help with a homework assignment very badly. Im not asking for you to do my homework, but any hints are very very welcome.

The assignment is as follows:

Quote:
Write a program that prints a checkerboard of given dimensions. The provided main function prompts the user for the size of the board (note that x and y dimensions do not have to be equal) and for the size of individual squares (again, the dimensions of a square do not have to be equal). The following is an example of 8 x 8 board made out of 5 x 3 squares:

( I couldn't get the chest board he made to copy/paste properly)


The printout must include centered top and side labels for columns and rows. The size of the board will not exceed 9 x 9 and both dimensions of a square must be odd.

The program must check whether the parameters entered by a user are valid (e.g., greater than zero, a board size greater than 9, or a square dimension is not odd). If any of the parameters is invalid, the program should print an error message and exit.

Add your code to the provided main function. Except for adding your code, you must not modify the given code. You can either download the code or copy it to you account using the following Unix command (note the dot at the end of the line):
The code that he provides us is

Quote:
#include <iostream>
using namespace std;

// prototype

int printBoard(int x, int y, int xSq, int ySq);
// Prints x times y "chess" board using xSq times ySq squares.
// Returns a nonzero value if an invalid param specified
// zero otherwise.

// your code goes here

int main () {
int x, y, xSq, ySq;

cout << "Enter horizontal dimension of the board : ";
cin >> x;
cout << "Enter vertical dimension of the board : ";
cin >> y;
cout << "Enter horizontal size of a square : ";
cin >> xSq;
cout << "Enter vertical size of a square : ";
cin >> ySq;

if (printBoard(x,y,xSq,ySq))
cout << "Invalid parameter\n";

return 0;
}
Once again, Im not asking for anyone to do my work(though I wouldn't mind ) ,I just need any hints or advice about how to tackle this. I just don't have the right kind of my mind to be a programmer.

Thanks,

Josh/C++ noob
C++noob is offline   Reply With Quote
Old 03-24-2005, 03:31 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
Some pseudocode:
Code:
Read valueX
Read valueY
Read squareX
Read squareY
while(valueY--)
   While(valueX--)
     print(squares of size squareX)
   print(squares of size squareY)
into code that might look somethig like this: (not tested/compiled/anything)
Code:
while(valueY--)
   {
     /* print vertical line of chessboard */
     while (squareX--)
     {
        /* print horizontal line */
       while(valueX--)
          print('-');
       print('|');
      }
     print('\n');
     squareX = orig_squareX;
     /* print spaces and vertical lines */
     while(squareX--)
     {
         while(valueX--)
           print('-');
         print('|');
      }
     print('\n');
    }
But remember this, I'm drunk right now, so this might be a pointer in the wrong direction....
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 03-24-2005 at 03:52 PM.
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple question 'bout compiling c program if13121 Platform/API C++ 0 11-09-2004 10:36 PM
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 09:43 PM
Simple C program Spooky Standard C, C++ 1 10-22-2004 07:26 AM


All times are GMT -8. The time now is 01:26 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting