0% found this document useful (0 votes)
1K views9 pages

C++ Tambola

This C++ code implements a Tambola (Bingo) game with the following functionality: 1. It initializes the game board with numbers 1-100 and randomly distributes tickets to players. 2. It calls out random numbers and deletes them from the board and players' tickets. 3. It checks each ticket after each number is called to see if a player has won by getting all numbers on their ticket. 4. The game loops through calling numbers until all 100 numbers have been called or a player wins, at which point the user is prompted to play again.

Uploaded by

Vishal Madan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views9 pages

C++ Tambola

This C++ code implements a Tambola (Bingo) game with the following functionality: 1. It initializes the game board with numbers 1-100 and randomly distributes tickets to players. 2. It calls out random numbers and deletes them from the board and players' tickets. 3. It checks each ticket after each number is called to see if a player has won by getting all numbers on their ticket. 4. The game loops through calling numbers until all 100 numbers have been called or a player wins, at which point the user is prompted to play again.

Uploaded by

Vishal Madan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

<SOURCE CODE>

// The Game Begins...

#include<iostream.h> #include<conio.h> #include<process.h> #include<stdlib.h> #include<stdio.h>

struct Tambola {char name[30]; int ticket[10]; int top; }T[5]; // Players' Names // Array that contains tickets of players

int BOARD[10][10];

// The Gameboard Array

void introduction(); void delnum(int x); void deltick(int ticket[10], int num, int &y); void sort(int x,int a[10]); void displayboard(int BOARD[10][10]); void displaytickets(int ticket[10], int k);

void introduction() {int i; clrscr(); gotoxy(15,20); for(i=0;i<50;i++) cout<<"*"; gotoxy(36,25); cout<<"TAMBOLA"; gotoxy(15,30); for(i=0;i<50;i++) cout<<"*"; getch(); clrscr(); gotoxy(32,15); cout<<"Introduction\n\n";

cout<<"\n\n\n\n\tTambola is very popular in India. It is also called as Housie or Bingo. The game is presided over by a caller, whose job is to call out the numbers. The numbers are selected from 1 to 100. The caller begins to call number as they are randomly selected. The ticket has random numbers. Once a number is selected it cannot be selected again. As the number is called, the players check to see if that number appears on the ticket. When all the numbers on the ticket are cancelled, the player wins the game."; cout<<"\n\n\n\n\n\n\t\t\t***** ALL THE BEST *****"; getch();

void displayboard(int BOARD[10][10]) {int i,j; cout<<"\n\n\n"; for(i=0;i<10;i++) {cout<<'\n'; for(j=0;j<10;j++) {cout<<BOARD[i][j]<<"\t"; } } }

void delnum(int x) {int i,j; for(i=0;i<10;i++) {for(j=0;j<10;j++) {if(BOARD[i][j]==x) {BOARD[i][j]=0;

} } } }

void displaytickets(int ticket[10], int k) {int i,j; for(j=0;j<k;j++) { cout<<ticket[j]<<" "; }

void sort(int ticket[10]) {int i,j,temp; for(i=0;i<9;i++)

{for(j=0;j<9;j++) {if(ticket[j]>ticket[j+1]) {temp=ticket[j]; ticket[j]=ticket[j+1]; ticket[j+1]=temp; } } }

void deltick(int ticket[10], int num, int &y) {int i,pos,flag=0; for(i=0;i<y;i++) {if(ticket[i]==num) {flag=1; pos=i+1; break; } } if(flag==1) {for(i=pos-1;i<y;i++) {ticket[i]=ticket[i+1]; } y--; }

void main() {START: int n,i,j,k,l,num,flag,a[100]; char ch; clrscr(); randomize(); introduction();

clrscr(); cout<<"Enter the number of players : "; cin>>n; cout<<"\n\nEnter the names of the players : \n\n"; for(i=0;i<n;i++) {cout<<"Player "<<i+1<<" : "; gets(T[i].name); } // Entry Of Players

k=1; for(i=0;i<10;i++) {for(j=0;j<10;j++)

// Initialization Of Board

{BOARD[i][j]=k; k++; } }

for(i=0;i<n;i++) {for(j=0;j<10;j++) {again:

//Distribution Of Tickets

num=random(100)+1; T[i].ticket[j]=num; for(k=0;k<j;k++) {if(num==T[i].ticket[k]) goto again; } } T[i].top=10; }

for(i=0;i<n;i++) {sort(T[i].ticket); }

// Sorting Of Tickets

clrscr(); displayboard(BOARD); for(i=0;i<n;i++) {cout<<"\n\n\n";

cout<<T[i].name<<"'s ticket : "; displaytickets(T[i].ticket,10); } getch(); displayboard(BOARD);

i=0; do {clrscr(); again1: num=random(100)+1; a[i]=num; for(j=0;j<i;j++) {if(num==a[j]) goto again1; } delnum(num); displayboard(BOARD); cout<<"\n\nThe Lucky Number is : "<<num<<"\n\n"; for(k=0;k<n;k++) {deltick(T[k].ticket,num,T[k].top); if(T[k].top==NULL) {clrscr(); cout<<"\n\n\nBINGO.... "<<T[k].name<<" wins."; getch(); clrscr();

cout<<"\n\nDo You want to play again? (Y/N) : "; cin>>ch; if(ch=='y' || ch=='Y') {goto START; } else {exit(0); } } } for(l=0;l<n;l++) {cout<<"\n\n\n"; cout<<T[l].name<<"'s ticket : "; displaytickets(T[l].ticket,T[l].top); } getch(); i++; }while(i<=100); getch(); }

You might also like