Random chance
Apr 15, 2009 at 9:09pm UTC
Hi there, i started learning C++ 3 days ago and i am really excited.I wrote this small code and i wanna know if there is a way to Declare a certain value for the abortion chance?
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
#include <iostream>
using namespace std;
int random(int );
int main ()
{
srand(time(0));
int n,max,o,chance;
cout << "Put a random number:\n" ;
cin >> max;
o=random(max);
for (max=max; max>0; max--)
{
cout << max << ", " ;
if (max==random(o))
{
cout << "Something evil aborted the countdown\n\a" ;
break ;
}
}
return 0;
}
int random(int o) {
return rand()%o;
}
Last edited on Apr 15, 2009 at 9:11pm UTC
Apr 19, 2009 at 7:42pm UTC
What do you mean? Your code doesn't even use those variables, i mean 'chance' or 'n'. What are they for??
Topic archived. No new replies allowed.