The question: Get an integer value from the user to draw a cheassboard on the screen of that specified size. The black squares must be * and with any other chessboard there must always be a *(black square) in the bottom left corner.

PLEASE NOTE: I'm very new to c++ programming.

My problem now is every un-even number it shows the * in the bottom left corner but if i input an even number it gives a blank space(white square) in the lower left corner....?

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
  int num1;
  int n = 1, k = 1 ;
  cout << "Enter Checkered board size: " ;
  cin >> num1;
  cout << "\n\n";
 
 while(n <= num1)
 {
 k = 1 ;
 if ( n++ % 2 == 0)  cout << ' ' ;
 {
  while(k++ <= num)
  {
  cout<<"* " ;
  }
  cout << "\n\n" ;
 }
 }
  
  cout << "\n\n";
  system("PAUSE");	
  return 0;
}

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

>while(k++ <= num)

num is undeclared.

thnx sorry i didn't see that one. k i fixed it but still didn't solve my problem...

Member Avatar for iamthwee

Post what you expect the output to be.

if i put in i.e. 5 it shows:

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

but if i use 6 it shows:

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

the output i want is like 5 but with even and un-even numbers... i.e.: if i type 6 now i would like to see:

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

Anyone have an idea?! :-/

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.