Thursday, 7 June 2012

C++ Program for a Lottery Game

C++ Program for a Lottery Game



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


int fivemillion_winner()
{
ofstream fout;
char name[50];
char date[9];

fout.open("c:/windows/desktop/Lottery Jackpot Winners.txt", ios::out | ios::app);
cout << "Congratulations.  Enter the name you want in the high score book  ";
  cout << "\n\nEnter your Highscore name:  ";
  cin  >> name;

  cout << "\nEnter the date(dd/mm/yy):  ";
  cin  >> date;
  fout << date << "  -  " << name << endl;
  cout << "\nThankyou!";
fout.close();
return 0;
}

int main()
{
clrscr();
srand((unsigned)time(NULL));
  int player_num = 1;
  int p1guess = 0;
  int p2guess = 0;
  char over = 'y';
  int winner = rand() % 100 +1;

cout << "Welcome to the Lottery Game!!!!  The game where you can win prizes!!!.  " << endl;
cout << "Here are the Prizes\n\n";
cout << "  1. $5,000,000 - Number Bang On" << endl;
cout << "  2. $2,500,000 - Number One Off" << endl;
cout << "  3. $1,000,000 - Number Two Off" << endl;
cout << "  4. $500,000   - Number Three Off" << endl;
cout << "  5. $250,000   - Number Four Off" << endl << endl;
cout << "If you are more that five numbers off you win nothing...\n\n";

while (over != 'n') {
tryagain:;
cout << "Enter the number of Players(1 or 2):  ";
cin  >> player_num;

if (player_num > 2) {
    cout << "\nI SAID 1 OR 2!! NOT " << player_num << "!!!\n";
    goto tryagain;
    }
if (player_num == 1) {
    cout << "\nOne Player it is!!";
    cout << "\n\nEnter what you think the number is.  Between 1 and 100:  ";
    cin  >> p1guess;

       if (p1guess == winner) {
           cout << "\nTHATS THE EXACT NUMBER!! YOU WIN $5,000,000!!\n\n";
           fivemillion_winner();
           }
  else if ((p1guess == winner + 1) || (p1guess == winner - 1))
           cout << "\nYOU WIN $2,500,000.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p1guess == winner + 2) || (p1guess == winner - 2))
           cout << "\nYOU WIN $1,000,000.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p1guess == winner + 3) || (p1guess == winner - 3))
           cout << "\nYOU WIN $500,000.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p1guess == winner + 4) || (p1guess == winner - 4))
           cout << "\nYOU WIN $250,000.  The First Place Winner was:  " << winner << "\n\n";
     else
           cout << "Sorry.  You don't win anything.  The Winning Number was:  " <<winner << "\n\n";
  }

if (player_num == 2) {
    cout << "\nTwo Player it is!!";
    cout << "\n\nPlayer 1:  Enter what you think the number is.  Between 1 and 100:  ";
    cin  >> p1guess;
    cout << "\n\nPlayer 2:  Enter what you think the number is.  Between 1 and 100:  ";
    cin  >> p2guess;

       if (p1guess == winner) {
           cout << "\nTHATS THE EXACT NUMBER PLAYER 1!! YOU WIN $5,000,000!!\n";
           fivemillion_winner();
           }
  else if ((p1guess == winner + 1) || (p1guess == winner - 1))
           cout << "\nYOU WIN $2,500,000 PLAYER 1.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p1guess == winner + 2) || (p1guess == winner - 2))
           cout << "\nYOU WIN $1,000,000 PLAYER 1.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p1guess == winner + 3) || (p1guess == winner - 3))
           cout << "\nYOU WIN $500,000 PLAYER 1.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p1guess == winner + 4) || (p1guess == winner - 4))
           cout << "\nYOU WIN $250,000 PLAYER 1.  The First Place Winner was:  " << winner << "\n\n";
    else
           cout << "Sorry.  You don't win anything player 1.  The Winning Number was:  " <<winner << "\n\n";

       if (p2guess == winner) {
           cout << "\nTHATS THE EXACT NUMBER PLAYER 2!! YOU WIN $5,000,000!!\n";
           fivemillion_winner();
           }
  else if ((p2guess == winner + 1) || (p2guess == winner - 1))
           cout << "\nYOU WIN $2,500,000 PLAYER 2.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p2guess == winner + 2) || (p2guess == winner - 2))
           cout << "\nYOU WIN $1,000,000 PLAYER 2.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p2guess == winner + 3) || (p2guess == winner - 3))
           cout << "\nYOU WIN $500,000 PLAYER 2.  The First Place Winner was:  " << winner << "\n\n";
  else if ((p2guess == winner + 4) || (p2guess == winner - 4))
           cout << "\nYOU WIN $250,000 PLAYER 2.  The First Place Winner was:  " << winner << "\n\n";
       else
           cout << "Sorry.  You don't win anything player 2.  The Winning Number was:  " <<winner << "\n\n";
  }
cout << "Would you like to try again(y/n)??  ";
cin  >> over;
system("cls");
  }
  getch();
  return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More