**************  TURN 1  ****************

	   |   |        |   |        |   |   
	 a | b | c    j | k | l    r | s | t
	__ |___| __  __ |___| __  __ |___| __
  	   |   |        |   |        |   |   
	 d | e | f    m | W | n    u | v | w 
   	__ |___| __  __ |___| __  __ |___| __
	   |   |        |   |        |   |    
	 g | h | i    o | p | q    x | y | z
	   |   |        |   |        |   | 
	
	   Where would you want to place your
   	   marker? a

	   You chose to place your marker on
	   block a.

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

How can you put a mark X on the block where the player have chosen?

So the next screen output will be..

**************  TURN 2  ****************

	   |   |        |   |        |   |   
	 X | b | c    j | k | l    r | s | t
	__ |___| __  __ |___| __  __ |___| __
  	   |   |        |   |        |   |   
	 d | O | f    m | W | n    u | v | w 
   	__ |___| __  __ |___| __  __ |___| __
	   |   |        |   |        |   |    
	 g | h | i    o | p | q    x | y | z
	   |   |        |   |        |   | 
       ****************************************

Can somebody please help me :/ (Correct my mistakes, if there is. Add some codes on it)
So far this is what I've done :|

printf("****************  TURN 1  ******************\n\n");
printf("    |     |        |     |        |     |     \n");
printf("  a |  b  | c    j |  k  | l    r |  s  | t   \n");
printf(" ___| ___ |___  ___| ___ |___  ___| ___ |___  \n");
printf("    |     |        |     |        |     |     \n");
printf("  d |  e  | f    m |  W  | n    u |  v  | w   \n");
printf(" ___| ___ |___  ___| ___ |___  ___| ___ |___  \n");
printf("    |     |        |     |        |     |     \n");
printf("  g |  h  | i    o |  p  | q    x |  y  | z   \n");
printf("    |     |        |     |        |     |     \n\n"); 
printf("Where would you want to place your \nmarker? ", cMarker1);
scanf("%c", &cMarker1);
printf("You chose to place your marker on \nblock %c\n", cMarker1);
printf("********************************************\n");

Recommended Answers

All 3 Replies

If you want to be able to alter the output you have to use variables not hardcode in the letters.

For this I used a string of characters alpha and placed them into the output.

#include <stdio.h>
#include <stdlib.h>

int main()
{
	char cMarker1;
	int i = 1;
	char alpha[] = "abcdefghijklmnopqrstuvwxyzW";
	while(1)
	{
		printf("****************  TURN %d  ******************\n\n", i);
		printf("    |     |        |     |        |     |     \n");
		printf("  %c |  %c  | %c    %c |  %c  | %c    %c |  %c  | %c   \n", alpha[0], alpha[1], alpha[2], alpha[9], alpha[10], alpha[11], alpha[17], alpha[18], alpha[19]);
		printf(" ___| ___ |___  ___| ___ |___  ___| ___ |___  \n");
		printf("    |     |        |     |        |     |     \n");
		printf("  %c |  %c  | %c    %c |  %c  | %c    %c |  %c  | %c   \n", alpha[3], alpha[4], alpha[5], alpha[12], alpha[26], alpha[13], alpha[20], alpha[21], alpha[22]);
		printf(" ___| ___ |___  ___| ___ |___  ___| ___ |___  \n");
		printf("    |     |        |     |        |     |     \n");
		printf("  %c |  %c  | %c    %c |  %c  | %c    %c |  %c  | %c   \n", alpha[6], alpha[7], alpha[8], alpha[14], alpha[15], alpha[16], alpha[23], alpha[24], alpha[25]);
		printf("    |     |        |     |        |     |     \n\n");

		printf("Where would you want to place your \nmarker? ");
		fflush(stdin);
		scanf("%c", &cMarker1);

		if( cMarker1 >= 'a' && cMarker1 <= 'z' )
		{
			alpha[cMarker1-'a'] = 'X';

			printf("You chose to place your marker on \nblock %c\n", cMarker1);
		}
		else if( cMarker1 == 'W' )
		{
			alpha[26] = 'X';

			printf("You chose to place your marker on \nblock %c\n", cMarker1);
		}
		else
			printf("Cannot place your marker at %c\n", cMarker1);
		printf("********************************************\n");

		i++;
	}

	return 0;
}

Replace line 23 with getchar(); because I learned that it is bad practice to use fflush(stdin); since it has undefined behavior with input streams and will only work on some compilers.

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.