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

 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review 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 *