C Project – Coin Toss Game

Get Certified in C Programming and Take Your Skills to the Next Level

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;
}

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *