Loop and other questions.
Apr 7, 2011 at 1:43pm UTC
Lottery style winner selection
I want to loop it from radom() back to prize()....how would I go about doing that?
Also is there an easy way of making sure my randomizer not repeat the same number? Mainly concern with
int prize() .
First time I use c++ in almost 4 years, so forgot most things. :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
using namespace std;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int random()
{
srand((unsigned ) time(NULL));
int numbers[1];
for (int i=0;i<1;i++)
{
numbers[i] = rand()%1000+1;
cout<<"\n\n" "" "***********************************\n" "* Congratulations #" <<numbers[i]<<" you won! *" "\n" "" "***********************************\n" <<endl;
cout<<"\nGiving you time to look it up on the list. :)\n" ;
}
//Pause, type something, press enter?
return 0();
}
int countdown()
{
int n;
printf ("\n\n\nStarting countdown...\n" );
for (n=2; n>0; n--)
{
printf ("%d\n" ,n);
wait (1);
}
printf ("0" );
return random();
}
int prize()
{
srand((unsigned ) time(NULL));
int numbers[1];
for (int i=0;i<1;i++)
{
numbers[i] = rand()%10+1;
cout<<"\nPrize #" <<numbers[i]<<" will be randomized now!" ;
cout<<"\nGood luck to you all. >.<" ;
//Pause, type something, press enter?
}
return countdown();
}
int main()
{
cout<<"***************************************\n" ;
cout<<"* *\n" ;
cout<<"* *\n" ;
cout<<"* Event name goes here *\n" ;
cout<<"* *\n" ;
cout<<"* *\n" ;
cout<<"***************************************\n" ;
cout<<"\n\nHello text!!!\n\n" ;
//Pause, type something, press enter?
return prize();
}
Last edited on Apr 7, 2011 at 1:45pm UTC
Topic archived. No new replies allowed.