แสดงบทความที่มีป้ายกำกับ โค๊ตโปรแกรมเป่ายิ๊งฉุบ ตอนที่ 2 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ โค๊ตโปรแกรมเป่ายิ๊งฉุบ ตอนที่ 2 แสดงบทความทั้งหมด

วันพฤหัสบดีที่ 15 กันยายน พ.ศ. 2554

โค๊ตโปรแกรมเป่ายิ้งฉุบ แข่งกับคอมฯ ตอนที่ 2

โค๊ตโปรแกรมเป่ายิ้งฉุบ แข่งกับคอมฯ  ตอนที่ 2
โปรแกรมภาษาซี ตอน โค๊ต ตัวอย่างโปรแกรมเป่ายิ๊งฉุบ ตอนที่ 2


#include <stdio.h>
#include <time.h>

main(){
    int i,ran,user2,cp1=0,cp2=0;
    char com,user;
    srand(time(0));
    printf("\t\tProgram game powjingshup r=rock p=paper s=scissor.\n");
    for(i=1;i<=5;i++){
            ran= (rand()%3)+1;

            if(ran==1){
                    com='r';
                }else if(ran==2){
                    com='p';
                }else{
                    com='s';
                }

            printf("\n\t%d. Time player1:",i);
            scanf("%c",&user);
            printf("\t%d. Time player2: %c \n",i,com);
                if(user=='r'){
                    user2=1;
                }if(user='p'){
                    user2=2;
                }if(user='s');
                    user2=3;



            if((ran==user2)){
                printf("\tEqual\n");
                }
            if((ran==1&&user2==3)||(ran==2&&user2==1)||(ran==3&&user2==2)){
                printf("\n\tPlayer2 Win!\n");
                cp2+=1;
            }else{
                printf("\n\tPlayer1 Win!\n");
                cp1+=1;
            }



    }


}

วันจันทร์ที่ 1 สิงหาคม พ.ศ. 2554

โปรแกรมภาษาซี ตอน โค๊ด ตัวอย่างโปรแกรมเป่ายิ๊งฉุบ ตอนที่ 1

โค๊ตโปรแกรมเป่ายิ้งฉุบ ตอนที่ 1
โปรแกรมภาษาซี ตอน โค๊ด ตัวอย่างโปรแกรมเป่ายิ๊งฉุบ ตอนที่ 1


#include <stdio.h>
#include <math.h>
    void main(){
        char num1[20],num2[20];
        printf("input num1 :");
        scanf("%s",num1);
        printf("input num2 :");
        scanf("%s",num2);

        if(strcmp(num1)==strcmp(num2)){
        printf("no win");

               }
        else if(strcmp(num1)==strcmp("rock")){
                 if(strcmp(num2)==strcmp("paper")){
                 printf("num2 win");
                 }
                 else{
                 printf("num1 win");
                 }
        }
        else if(strcmp(num1)==strcmp("paper")){
                 if(strcmp(num2)==strcmp("rock")){
                 printf("num1 win");
                 }
                 else{
                 printf("num2 win");
                 }
        }
        else if(strcmp(num1)==strcmp("scissors")){
                 if(strcmp(num2)==strcmp("paper")){
                 printf("num1 win");
                 }
                 else{
                 printf("num2 win");
                 }
        }
}