How to display chessboard using while | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to display chessboard using while

i have try many time, but it still not correct U_U anyone help please. They want us to display the chessboard with the given cell from user. Ex: user input 3 cell. display: ***___***___***___ ***___***___***___ ***___***___***___ ___***___***___*** ___***___***___*** ___***___***___*** The line is always 6 and the column is always 4 just that the amout of * or _ to display is input by user

28th Dec 2016, 2:17 AM
Otaku Tenjito
Otaku Tenjito - avatar
14 Respostas
+ 1
they want the user to imput the cell Ex: cin>>4 the cell change to ****____ cin>>6 the cell change to ******______ By what i mean is that the amout of * or _ is imput by user, but for only 1 time. @ Vishal
28th Dec 2016, 2:57 AM
Otaku Tenjito
Otaku Tenjito - avatar
+ 1
#include <iostream> //to make string output #include <string> using namespace std; int main() { Ā Ā Ā  string black; Ā Ā Ā  string white; Ā Ā Ā  int cells; Ā Ā Ā  int boardSize = 0; //starting number Ā Ā Ā  cout << "How many cells?: "; Ā Ā Ā  cin >> cells; Ā Ā Ā  //add to black and white the number of cells Ā Ā Ā  for (int x = 0; x < cells; ++x) { Ā Ā Ā  Ā Ā Ā  black += "*"; Ā Ā Ā  Ā Ā Ā  white += "_"; Ā Ā Ā  } Ā Ā Ā  //6 for 6 lines Ā Ā Ā  while (boardSize < 6) { Ā Ā Ā  Ā Ā Ā  //3 for black and white 3 times Ā Ā Ā  Ā Ā Ā  for (int i = 0; i < 3; ++i) { Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  cout << black << white; Ā Ā Ā  Ā Ā Ā  } Ā Ā Ā  Ā Ā Ā  cout << endl; Ā Ā Ā  Ā Ā Ā  ++boardSize; Ā Ā Ā  } }
28th Dec 2016, 4:51 AM
Vishal++
Vishal++ - avatar
+ 1
Convert that for to while. This is something u must do
28th Dec 2016, 8:06 AM
Vishal++
Vishal++ - avatar
+ 1
If you really mean the word in ur name "Otaku". You must really learn coding to every last bit!
28th Dec 2016, 8:08 AM
Vishal++
Vishal++ - avatar
+ 1
xD i dun know if i should say thank you or kill you insteadšŸ˜‚ Thank u hahahha i will try
28th Dec 2016, 8:43 AM
Otaku Tenjito
Otaku Tenjito - avatar
0
i use in c++ for my homework
28th Dec 2016, 2:26 AM
Otaku Tenjito
Otaku Tenjito - avatar
0
cool, i am planning on using c# in a game engine, its my 1st attempt.
28th Dec 2016, 2:31 AM
Gavin Streete
Gavin Streete - avatar
0
x'D i'm just a beginner, my classmate are all boys and they catch up easily and they try hard, while i study 3 majors and dun do any excersices, just that i start to try hard from now on, ;_; but i dun have much time since i am always study and tired af
28th Dec 2016, 2:33 AM
Otaku Tenjito
Otaku Tenjito - avatar
0
@Otaku You want to display a chessboard on the screen with *** as black and ___ as white? If yes, what do u mean be user inputs 3?
28th Dec 2016, 2:54 AM
Vishal++
Vishal++ - avatar
0
Understood. And its 6x6 chessboard instead of original 8x8 chessboard. Otaku, how about u start writing the program? And when ur stuck I can help
28th Dec 2016, 4:09 AM
Vishal++
Vishal++ - avatar
0
šŸ˜‚ ok, but i didn't display anythings that is why i wonder wth is wrong with it i will write it to u, but i have 4 class this afternoon, so i can't write it now ad thank q so much
28th Dec 2016, 4:13 AM
Otaku Tenjito
Otaku Tenjito - avatar
0
Thank you so much!! but i haven't write the code yet. I will test it tonight!!! * bow* really thank you.
28th Dec 2016, 6:09 AM
Otaku Tenjito
Otaku Tenjito - avatar
0
;_; but he said to only use while or do not for
28th Dec 2016, 7:47 AM
Otaku Tenjito
Otaku Tenjito - avatar
- 1
how is c++? i have never tried it before. you using an game engine or Microsoft visual?
28th Dec 2016, 2:21 AM
Gavin Streete
Gavin Streete - avatar