Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > General Gambling > Computer Technical Help
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-15-2005, 09:00 PM
mscags mscags is offline
Senior Member
 
Join Date: Mar 2005
Location: Between Two Hot Twins
Posts: 713
Default C++ Lottery Program

So I'm in an intro class this semester and I have to write a lottery program. I was wondering if any of you guys that are programers or what not would mind taking a look at the code and see if you can find any glaring mistakes. A couple of things I'm not sure about 1) I need to randomize the numbers in the lottery array. I'm not sure if the code for that is right. 2) I need the user to be able to repeat the program if desired. Is my way alright or should I do something different? I was supposed to use functions for this assignment (hence all of the functions) Anyway, thanks in advance.

Mike

//This is a lottery program. It will ask the user in imput five numbers and will then store
//them as an array. The program will then generate 5 numbers and will check to see if they match.
//If they do, the user will be proclaimed the grand winner!

#include <iostream>
#include <cstdlib>
using namespace std;

void lottery() //Gets the random numbers.
{
unsigned seed;
cout << "Enter a seed value."
cin >> seed;
srand(seed);
y = 1 + rand() % 36;
cout << rand(LotteryNumber[0];
cout << rand(LotteryNumber[1];
cout << rand(LotteryNumber[2];
cout << rand(LotteryNumber[3];
cout << rand(LotteryNumber[4];
cout << rand(LotteryNumber[5];

return 0;
}

void numbercompare() //Compares to see if the user won the lottery.
{
if (LotteryNumber[0] == UserArray[0] && LotteryNumber[1] == UserArray[1] && LotteryNumber[2] == UserArray[2] &&
LotteryNumber[3] == UserArray[3] && LotteryNumber[4] == UserArary[4] && LotteryNumber[5] == UserArray[5])
cout << "CONGRATULATIONS!!! YOU'RE THE GRAND WINNER!!!";
else
cout << "Sorry you didn't win the grand prize. Please try again!";

return 0;
}


void UserNumbers() //Asks the user to imput five numbers to use for the lottery program.
{
const int Numbers = 5 //Amount of numbers needed for the lottery program.
int LotteryNumbers[5], UserArray[Numbers];
int count;

cout << "Enter the five numbers that you want to use for the lottery program.";
for (count = 0; count < Numbers count++)
cin >> UserArrary[count];
cout << "Here are the numbers that you entered.";
for (int index = 0; index < Numbers; index++;
cout << UserArray[index] << endl;

return 0;

}

int main()
{
char decision;

cout << This is the beginning of the lottery program.";
UserNumbers();
lottery();
numbercompare();
cout << "Would you like to repeat the program? Y or N";
cin >> decision;
if (decision == 'Y' or 'y')
UserNumbers();
else
cout << "Thanks for playing the lottery program!";
return 0;
}
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.