weird, i dun get if()?
-
can someone please help me with this piece of code. i was at work and bored so i started writing this. It should generate 9999 random numbers and count how many times it was 5 (according to me anyways). i'm really confused because i've programmed some heavy stuff already in MFC and i just dont get this. The problem is that v turns out to be 75536 every time i run it... #include #include #include #include #include #include int main(int argc, char *argv[]) { srand((unsigned)time(NULL)); int i; int v; for (i=0;i<=9999;i++) { int a = rand()%(9-0); cout << a; if(a=5) { v = v+1; } } cout << "\n"; cout << "\n"; cout << "The number of times 5 was generated:"; cout << v; cout << " / 9999\n"; getch(); return 0; } Thankya Kuni
-
can someone please help me with this piece of code. i was at work and bored so i started writing this. It should generate 9999 random numbers and count how many times it was 5 (according to me anyways). i'm really confused because i've programmed some heavy stuff already in MFC and i just dont get this. The problem is that v turns out to be 75536 every time i run it... #include #include #include #include #include #include int main(int argc, char *argv[]) { srand((unsigned)time(NULL)); int i; int v; for (i=0;i<=9999;i++) { int a = rand()%(9-0); cout << a; if(a=5) { v = v+1; } } cout << "\n"; cout << "\n"; cout << "The number of times 5 was generated:"; cout << v; cout << " / 9999\n"; getch(); return 0; } Thankya Kuni
-
can someone please help me with this piece of code. i was at work and bored so i started writing this. It should generate 9999 random numbers and count how many times it was 5 (according to me anyways). i'm really confused because i've programmed some heavy stuff already in MFC and i just dont get this. The problem is that v turns out to be 75536 every time i run it... #include #include #include #include #include #include int main(int argc, char *argv[]) { srand((unsigned)time(NULL)); int i; int v; for (i=0;i<=9999;i++) { int a = rand()%(9-0); cout << a; if(a=5) { v = v+1; } } cout << "\n"; cout << "\n"; cout << "The number of times 5 was generated:"; cout << v; cout << " / 9999\n"; getch(); return 0; } Thankya Kuni
-
can someone please help me with this piece of code. i was at work and bored so i started writing this. It should generate 9999 random numbers and count how many times it was 5 (according to me anyways). i'm really confused because i've programmed some heavy stuff already in MFC and i just dont get this. The problem is that v turns out to be 75536 every time i run it... #include #include #include #include #include #include int main(int argc, char *argv[]) { srand((unsigned)time(NULL)); int i; int v; for (i=0;i<=9999;i++) { int a = rand()%(9-0); cout << a; if(a=5) { v = v+1; } } cout << "\n"; cout << "\n"; cout << "The number of times 5 was generated:"; cout << v; cout << " / 9999\n"; getch(); return 0; } Thankya Kuni
if (a=5) Shouldn't that be
if (a==5)
? --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire." -- Chris Maunder -
if (a=5) Shouldn't that be
if (a==5)
? --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire." -- Chris Maunder -
Perhaps you should initialize v variable at the start of the program :) int v = 0; Miroslav Rajcic http://www.spacetide.com
-
Perhaps you should initialize v variable at the start of the program :) int v = 0; Miroslav Rajcic http://www.spacetide.com
-
can someone please help me with this piece of code. i was at work and bored so i started writing this. It should generate 9999 random numbers and count how many times it was 5 (according to me anyways). i'm really confused because i've programmed some heavy stuff already in MFC and i just dont get this. The problem is that v turns out to be 75536 every time i run it... #include #include #include #include #include #include int main(int argc, char *argv[]) { srand((unsigned)time(NULL)); int i; int v; for (i=0;i<=9999;i++) { int a = rand()%(9-0); cout << a; if(a=5) { v = v+1; } } cout << "\n"; cout << "\n"; cout << "The number of times 5 was generated:"; cout << v; cout << " / 9999\n"; getch(); return 0; } Thankya Kuni
Also, you never initialize v to be 0 -- probably explains why v is always 75536.
-
can someone please help me with this piece of code. i was at work and bored so i started writing this. It should generate 9999 random numbers and count how many times it was 5 (according to me anyways). i'm really confused because i've programmed some heavy stuff already in MFC and i just dont get this. The problem is that v turns out to be 75536 every time i run it... #include #include #include #include #include #include int main(int argc, char *argv[]) { srand((unsigned)time(NULL)); int i; int v; for (i=0;i<=9999;i++) { int a = rand()%(9-0); cout << a; if(a=5) { v = v+1; } } cout << "\n"; cout << "\n"; cout << "The number of times 5 was generated:"; cout << v; cout << " / 9999\n"; getch(); return 0; } Thankya Kuni