Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
codeblock microsoft
04-12-2013, 09:01 PM, (This post was last modified: 04-12-2013, 10:01 PM by troy.)
Post: #1
codeblock microsoft
nak tnye.. knpe code aku ni xleh run dkn microsoft visual eh?
~.~ kluaq error. HmmHmm
kat codeblock boleh saja.

Code:
#include <stdio.h>
  int main()


  {
        int winner = 0, count = 0;

        int data[9], index, sign, player, flag, x, k, j;

        for (x = 0; x < 9; x++)
            data[x] = ' ';


        while (count < 9) {
                flag = 0;


                printf("\n\tAssignment 2 : Introduction to Programming");
                printf("\n\tLecturer : Dr. ---\n");

                printf("\n\tThis is Tic Tac Toe Game!");
                printf("\n\tKeep Calm And Play\n\n");
                printf("\n\tPlayer 1 play as X");
                printf("\n\tPlayer 2 play as O");
                printf("\n\n");
                printf("\t\t\t  %c | %c  | %c  \n", data[0], data[1], data[2]);
                printf("\t\t\t----*----*----\n");
                printf("\t\t\t  %c | %c  | %c  \n", data[3], data[4], data[5]);
                printf("\t\t\t----*----*---\n");
                printf("\t\t\t  %c | %c  | %c  \n", data[6], data[7], data[8]);
                if (count % 2 == 0)
                {
                        sign = 'X';
                        player = 1;
                } else {
                        sign = 'O';
                        player = 2;
                }
                printf("\n\nPlayer %d's turn. Please choose a number between 1 to 9: \nNumber : ", player);
                scanf("%d", &index);
                if (index < 1 || index > 9)
                {
                        printf("\n\n\n\t\t****Please enter index between 1 to 9 only ^_^****\n\n\n");
                        continue;
                }
                if (data[index - 1] == 'X' || data[index - 1] == 'Y')
                {
                        printf("\n\n\n\t\t****Sorry, Please choose another position****\n\n\n");

                        continue;
                }
                data[index - 1] = sign;
                count++;

                for (x = 0; x < 9; x++)
                {
                        if (x % 3 == 0)
                                flag = 0;

                        if (data[x] == sign)
                                flag++;

                        if (flag == 3)
                {
                                winner = 1;
                                goto win;
                }
                }

                flag = 0;
                for (x = 0; x < 3; x++) {
                        for (k = x; k <= x + 6; k = k + 3) {
                                if (data[k] == sign)
                                        flag++;
                        }
                        if (flag == 3) {
                                winner = 1;
                                goto win;
                        }
                        flag = 0;
                }
                if (
                    (data[0] == sign && data[4] == sign && data[8] == sign)
                    ||
                    (data[2] == sign && data[4] == sign && data[6] ==  sign)
                    )
                {
                        winner = 1;
                        goto win;
                }
        }
  win:
        system("cls");
        printf("\n\n");
        printf("\t\t\t  %c | %c  | %c  \n", data[0], data[1], data[2]);
        printf("\t\t\t----*----*----\n");
        printf("\t\t\t  %c | %c  | %c  \n", data[3], data[4], data[5]);
        printf("\t\t\t----*----*---\n");
        printf("\t\t\t  %c | %c  | %c  \n\n", data[6], data[7], data[8]);
        if (winner) {
                printf("Congratulation Player %d ! You have WON!\n", player);

        } else {
                printf("Sorry :(,the game was a TIE !\n");

                printf("Try again next time..!");
        }

        {
            printf("\n\n");
            printf("\nCoding by:\n");
            printf("\n---");
            printf("\n---)");
            printf("\n---");
        }
        system("pause");
        return 0;

  }

assignmt haritu lect ak xleh nak run kat pc dia.
kena bawak lappy sendiri run dpn dia.Fuck Yeah
yg ni asgmnt lain dia suruh tukar guna microsoft. =.
tulunnn

eh. dah jumpa problem dia. hea. Peaceee
Reply
04-12-2013, 10:51 PM, (This post was last modified: 04-12-2013, 10:52 PM by syahmiazhar.)
Post: #2
RE: codeblock microsoft
kluaq error apa?

ooo da settle... oke
[Image: 1Z3i3.jpg]
Reply


Forum Jump: