Site icon DataFlair

C Project – Coin Toss Game

Program 1

#include<stdio.h>
#include<conio.h>
#include<time.h>
#define clrscr() system("cls")
int main()
{
    clrscr();
    int userchoice,coinchoice;
    srand(time(0));
    printf("\n Welcome in the coin toss Game ! \n");
    printf("\n-------------------------------------");
    printf("\nChoose 1. Head \nChoose 2.  Tail \n ");
    printf("\n--------------------------------------");
    printf("\n Enter your choice");
    scanf("%d",&userchoice);
    coinchoice=(rand()%2)+1;
    // printf("\n user choice : %d",userchoice);
    // printf("\n coin choice : %d",coinchoice);
    if(coinchoice==1)
    printf("\n Coin landed Head ! \n ");
    else
    printf("\n Coin landed Tail ! \n ");
    if(userchoice==coinchoice)
    printf("******Congrats you won the toss******");
    else
    printf("----------Sorry ! you loss the toss------------");

    return 0;
}

 

Exit mobile version