Site icon DataFlair

C++ Project – Coin Toss Game

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Coin Toss Game
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define clrscr() system("cls")
using namespace std;
int main()
{
    clrscr();
    srand(time(0)); 
    int coinchoice,userchoice;
    coinchoice=rand()%2+1;
    cout<<"\n-------------Coin Toss Game--------------";
    cout<<"\n 1. Choose 1 for Head \n 2. Coose 2 for Tail";
    cout<<"\n---------------------------------------------";
    cout<<"\n Enter user choice: ";
    cin>>userchoice;
    if(coinchoice==1)
       cout<<"\n Coin landed Head...";
    else
      cout<<"\n Coin landed Tail...";   
    
    if(userchoice==coinchoice)  
     cout<<"\nCongrats You won the toss";
     else
     cout<<"\nOops You lose the toss";

    return 0;
}

 

Exit mobile version