#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<string.h>

int n=0;   // current no. of players ( to add to next one)
int num=0; // total number of players


class date
{
  public:
  int dd;
  int mm;
  int yy;
};

class players
{
  public:

	char name[30];
	date dob;
	char userid[30];
	char pass[30];
	char sec_q[30];
	char sec_a[30];
	float bet;
	float bal;
	int rounds_won;
	int tot_rounds;
	float win;

	void create_account();
	void log_in();
	void forgot_pass();
	void delete_account();
	void highscores();
	void display_players();




 }p[100];

 void players::create_account()
  {
	  fstream f;

	  f.open("player_details.dat",ios::app|ios::out);

	  char pass1[30],pass2[30],id[30];

	  cout<<"SIGN UP \n\n"<<endl;

	  cout<<"PLAYER DETAILS\n "<<endl;
	  cout<<"FULL NAME"<<endl;gets(p[n].name);
	  cout<<"DOB (dd/mm/yy)"<<endl;cin>>p[n].dob.dd>>p[n].dob.mm>>p[n].dob.yy;
	  A:
	  {
	  cout<<"SCREEN NAME"<<endl;gets(id);
			//check for availiblity

			int i=0;
			while(f)
			{
				f.read((char *)&p[i] , sizeof(p[i]));
				if( strcmpi(id,p[i].userid)==0)
				{	cout<<"User Id already taken. Please try a new Id"<<endl;
					goto A;
				}

				else
				strcpy(p[i].userid,id);

			  i++;

			 }

	  }// end of label A

	  B:
	  {
	  cout<<"PASSWORD"<<endl;gets(pass1);
	  cout<<"RE-ENTER PASSWORD"<<endl;gets(pass2);
		//compare passwoprds
		if (strcmp(pass1,pass2)==0)
		  {  strcpy(pass2,p[n].pass);}
		else
		{	cout<<"Passwords do not match. Please try again."<<endl;
			goto B;
		}
	  }//end of label B

	  cout<<"SECURITY QUESTION"<<endl;gets(p[n].sec_q);
	  cout<<"SECURITY ANSWER"<<endl;gets(p[n].sec_a);

	  p[n].tot_rounds=0;

	  f.write((char *) & p[n],sizeof(p[n]));

	  clrscr();
	  cout<<"ACCOUNT SUCCESSFULLY CREATED"<<endl;

	  n++;            // to increase no. of players

 f.close();

 }

  void players::log_in()
  {
		fstream f;

		f.open("player_details.dat",ios::in);

	  A:
	  {
		cout<<"USER ID "<<endl; gets(name);
		cout<<"PASSWORD"<<endl; gets(pass);




		// To check if user name exists and check pass

		int i=0,pos=-1;

			while(f)
			{
			  f.read((char *)&p[i] , sizeof(p[i]));

			  if(strcmp(name,p[i].name)==0)
			  {
					if( (strcmp(pass,p[i].pass)==0))
				  {
					cout<<"User id and password match!"<<endl;
					getchar();

					display_players();

				  }
				  else { cout<<"User Id and Password did not match. Please try again"<<endl;  getchar(); goto A;}
			  }
			  i++;


			}

			// f.read((char *)&p[pos] , sizeof(p[pos]));

		  /*if(pos!=-1 && (strcmp(pass,p[pos].pass)==0))
		  {
		  cout<<p[pos].name<<" "<<p[pos].userid<<endl;
		  cout<<"User id and password match!"<<endl;
		  getchar();
		  }
		  */





		}// end of label A

	f.close();

	}

  void players::forgot_pass()
  {
	  fstream f;

	  f.open("player_details.dat",ios::in);

	  char id[30];
	  A:
	  {
	  cout<<"Enter USER ID "<<endl; gets(id);

	  int i=0,pos,chk=-1;

	  while(f.read((char *) & p[i],sizeof(p[i])))
	  {
		f.read((char *) & p[i],sizeof(p[i]));
		if(strcmp(id,p[i].userid)==0)
		 {pos=i;chk=1;}
	  }

	 date dob1;

	 if(chk==1)
	 {
		f.read((char *) & p[pos],sizeof(p[pos]));

		char sec_a1[30];

		cout<<p[pos].sec_q<<endl;
		cout<<"Enter Security Answer"<<endl; gets(sec_a1);
		cout<<"Enter DOB(dd/mm/yy)"<<endl; cin>>dob1.dd>>dob1.mm>>dob1.yy;

			if( strcmp(sec_a1,sec_a)==0 && dob1.dd==p[pos].dob.dd && dob1.mm==p[pos].dob.mm && dob1.yy==p[pos].dob.yy)
				cout<<" Password is :- "<<p[pos].pass;

			else
				cout<<"Sorry the details you entered did not match with our records"<<endl;
	 }

	 else

	  {cout<<"Invalid User Id. please try again"<<endl;goto A;}

	}//end of label A

 f.close();

 }

 void players::delete_account()
 {
	 ifstream f;
	 ofstream f1;

	 f.open("player_details.dat",ios::in);
	 f1.open("temp.dat",ios::out);

	 int i=0,pos=-1,chk=-1;

	 A:
	  {
		cout<<"Enter the User Id you want to delete"<<endl;gets(name);
		cout<<"Enter the Password"<<endl;gets(pass);

		// To check if pass is right and compare user id



			while(f)
			{
			  f.read((char *)&p[i] , sizeof(p[i]));
			  if(strcmp(name,p[i].name)==0) pos=i;
			  i++;
			}

			f.read((char *)&p[pos] , sizeof(p[pos]));
		  if(strcmp(pass,p[pos].pass)==0) chk=1;

		  else if(pos==-1) { cout<<"User Id and Password did not match.please try again"<<endl; goto A;}

		}// end of label A

	 i=0;

	 if(chk==1)
	 {
		while(f)
			{
			f.read((char *)&p[i],sizeof(p[i]));

			if(i!=pos)
			f1.write((char *)&p[i],sizeof(p[i]));
			else
         {cout<<" ";}

			i++;
			}
	}

	f1.close();
	f.close();

	remove("player_details.dat");
	rename("temp.dat","player_details.dat");

 }

 void players::highscores()
 {
	 fstream f;

	 f.open("highscores.dat",ios::out | ios::in);



	 f.close();
 }

 void players::display_players()
 {
		fstream f;
		int i=0;

		f.open("player_details.dat",ios::in);

		while (f)
		{
		f.read((char *)&p[i], sizeof (p[i]));
		i++;
		}

      clrscr();

		gotoxy(1,1);cout<<"Name";
		gotoxy(5,1);cout<<"User id";

		int j;


		for(i=0,j=2;i<n;i++,j++)
		{
			gotoxy(1,j);cout<<p[i].name;
			gotoxy(5,j);cout<<p[i].userid;
		}

 }


 void rules()
	{
					clrscr();
						cout<<"                     ALL ABOUT BLACKJACK 2.75.93\n\n"<<endl;
						cout<<" BLACKJACK IS A VERY POPULAR CASINO GAME WHICH IS PLAYED BETWEEN THE PLAYERS AND THE CASINO DEALER."<<endl;
						cout<<"\n Blackjack 2.75.93 is a simple and a modified form of the real Blackjack casino game."<<endl;
						cout<<"\n This game is a 2 player game and cannot be played with the CPU. "<<endl;

						getchar();
						clrscr();

						cout<<"\n\nRULES OF BETTING... \n \n Basically , Player 1 and Player 2 already have 500$ in their blackjack accounts on commencement of a new game."<<endl;
						cout<<"Each player is asked to bet a certain amount of cash before a round of dealing starts. He/She may bet anywhere between 50$ to how much ever they have left in their account."<<endl;
						cout<<"\n\n The player who wins a particular round gets the bet amount of the other player of that round and this is added to his account balance before the next round. In case of a draw ,they get back only their own bet amount."<<endl;
						cout<<"\n\n If these players want to play more , they may continue to the next round and again bet for that round. But once either of the player's account balance reaches below 50$ , He/She is out of the game and the other player wins the Game."<<endl;
						getchar();clrscr();

						cout<<"\n\n DEALING PATTERN..."<<endl;

						cout<<"\n= The aim of this game is too get a sum total of 21 from your cards. If a Player's dealt cards sum up to 21 , Then he straight away wins that round."<<endl;
						cout<<"= Firstly,each player gets a 2 alternate chances to generate 1 card out of the deck , by saying'HIT' when it is his/her turn. After two turns each, each player has two cards and then the play goes to Player 1 to continue with the   'HIT' or 'STAY-( STAY-which means that the player is satisfied with the dealt cards and wants to stop 'HITTING'."<<endl;
						cout<<"\n\n Once Player 1 decides to 'STAY', It is Player 2's turn to 'HIT' or 'STAY'.He/She may continue to do so until he/she is also satisfied with the cards dealt."<<endl;
						cout<<"\n \n= After both the players have stopped with the dealing of the cards, The sum total of their respective cards is calculated and the player with the highest total wins that round.But there are certain rules regarding who wins and who loses."<<endl;

						getchar();clrscr();

						cout<<"\n\n HOW DO YOU WIN A ROUND OF BLACKJACK...?"<<endl;
						cout<<"\n= The scoring system goes like this:-\nAce- 1point\nFace cards-10 points\nRest of the cards- Points=the face value of the card"<<endl;
						cout<<"\n The player's whose points add up closest to 21 , but not greater than 21, wins the round."<<endl;

						getchar();clrscr();

						cout<<"\n\n WHAT IS A BLACKJACK...?"<<endl;
						cout<<"\n= When a player's points on the cards add up to a 'Perfect 21' , He/she is said to have got a Blackjack! and wins the round."<<endl;
						cout<<"\n\n WHAT IS A BUST...?"<<endl;
						cout<<"\n= When any player's points sum upto greater than 21, He/she is BUSTED and loses that round. "<<endl;
						cout<<"\n\n Thus , the 'WINNER' of the game Blackjack is the one who beats the other player in terms of account balance."<<endl;
						cout<<" \n\n"<<endl;

						getchar();clrscr();
						cout<<" Now , that you have the read the rules of BLACKJACK, let's play." <<endl;
						getchar();
						clrscr();


	}// end of rules


 void details()
		{
			clrscr();
			gotoxy(1,2);
			cout<<"                COMPUTER PROJECT , CLASS 11 B      \n"<<endl;
			cout<<"\n            BLACKJACK 2.75.93 "<<endl;
			cout<<"\nDeveloped by,\n Hriday Thakkar B,Dhawal joharapurkar \n Class 11 B,\n National Public School -Rnr, \n Bangalore-10."<<endl;
			cout<<"\n Mail us your comments and suggestions at: <MY EMAIL ADDRESS HERE THAT WAS SNIPPED BY MODERATOR>"<<endl;
			cout<<""<<endl;

			getchar();


		}


 void main()
 {
	 clrscr();
	 cout<<"WELCOME TO NPS CASINO "<<endl;
	 getchar();
	 clrscr();

	 int ch_2;

 do
 {
	pg_2:

	{
		 clrscr();

		 cout<<"1. Play Game"<<endl;
		 cout<<"2. Sign Up"<<endl;
		 cout<<"3. Delete Account"<<endl;
		 cout<<"4. High Scores"<<endl;
		 cout<<"5. Rules"<<endl;
		 cout<<"6. Developers"<<endl;
		 cout<<"7. Exit Game "<<endl;
		 cout<<"8. Display Player Details \n"<<endl;
		 cout<<"Enter your choice"<<endl;
		 cin>>ch_2;

		 switch(ch_2)
		 {

			case 1:

			pg_3:  //page 3

			{
			 clrscr();

			 int ch_3;

			 clrscr();

			 cout<<"1. Doubleplayer";
			 cout<<"\n2. Go Back";

			 cout<<"Enter your choice"<<endl;
			 cin>>ch_3;

				  switch(ch_3)
				  {
					  case 1:

						pg_3_1:      // from page 3 to 4 thru singleplayer
						 {
							int ch_3_1;

							clrscr();

							cout<<"1. Log In"<<endl;
							cout<<"2. Forgot Password?"<<endl;
							cout<<"3. Go back"<<endl;


								cout<<"Enter your choice"<<endl;
								cin>>ch_3_1;

								  switch(ch_3_1)
								  {
									 case 1:

										 clrscr();
										  cout<<"PLAYER 1 LOG IN"<<endl;
										  getchar();
										  p[0].log_in();

										 clrscr();
										  cout<<"PLAYER 2 LOG IN"<<endl;
										  getchar();
										  p[0].log_in();

										 break;

									 case 2:

										 p[0].forgot_pass();
										 break;

									 case 3:

										goto pg_3;
										break;


									 default :
										cout<<"Invalid choice.Please try again";goto pg_3_1;

									}// end of switch case

						}// end of pg_3_1



						case 2:

								goto pg_2;

						default :
								cout<<"Invalid choice.Please try again";goto pg_3;


				  }//end of play game

			 }//end of pg_3


				case 2:

				  p[0].create_account();getchar();clrscr();
				  break;

				case 3:

				  p[0].delete_account();getchar();clrscr();
				  break;

				case 4:

					p[0].highscores();getchar();clrscr();
					break;

				case 5:

				  rules();clrscr();
				  break;

				case 6:

				  details();clrscr();
				  break;

				case 7:

					exit(0);
					break;

				case 8:
				  p[0].display_players();
				  getchar();
				  clrscr();
				  break;

				default :

				  cout<<"Invalid CHoice.PLease try again"<<endl;

			 }//end of switch case

		}// end of pg_2

	 }while(ch_2<=8);


}//end of main

Recommended Answers

All 3 Replies

You need to be specific about what the issues are. As the great (moderator) WaltP will tell you, "we're not mind readers."

The account delete is not working. The logging in doesn't work. I think the create function itself is creating a doubt.

Line 60,122,123 (etc) never use gets. You can overrun your buffer and crash your program. The gotos make everything a little sloppy.

Can you elaborate more on those issues? What about it doesn't work? Is it the file reading or the password matching? You can shed some light on these issues by running it through a debugger or by cout'ing your variables along the way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.