Nested Loops ~ Need help!!!

I've literally spent an over hour just trying to print this 100 times but I can't seem to figure it out. Any help would be greatly appreciated! Thank you.


#include <iostream>
#include <ctime>

using namespace std;

int main(int argc, char * args[]) {
srand(time(0));
int i, j;
for (int i = 0; i < 6; ++i) {
for (int j = 0; j <= 100; i++) {
int n = rand() % 16;
if (n <= 9) cout << n;
else if (n == 10) cout << "A";
else if (n == 11) cout << "B";
else if (n == 12) cout << "C";
else if (n == 13) cout << "D";
else if (n == 14) cout << "E";
else if (n == 15) cout << "F";

}
}
cout << endl;

cin.get(); cin.get();
}
Last edited on
in line
for(int j=0;j<=100;i++
instead of i++ use j++, see:
for(int j=0;j<=100;j++

and use #include<stdlib.h>

for more reference on nested for loops see: http://goo.gl/nmmCTM
All I really see it at very end of code you should need a return0; after the cin.get and what is causing the loop instead of running it 100 ish times is you have i++ and not a j++ you initiate the never ending looop there. Not sure what you are trying to do but with this change it will run a random generator 108 times and display the result you defined on the screen.
Topic archived. No new replies allowed.