Right, I haven't been working long and I've come up with this so far, no compile errors - just logic problems.
Code:
// 48 - 122
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
srand(time(NULL));
int character = 0;
for(int i = 1; i >= 8; i++){
character = rand() % 75 + 48;
char letter= 0;
//checks to see if our random character is a number or letter
if(character >= 48 && character <= 57){
letter = static_cast<char>(character);
cout << letter;
}
if(character >= 65 && character <= 90){
letter = static_cast<char>(character);
cout << letter;
}
if(character >= 97 && character <= 122){
letter = static_cast<char>(character);
cout << letter;
}
else{
continue; // should continue doing the loop...
}
} //end of loop
system("PAUSE");
return EXIT_SUCCESS;
}
It goes straight to the system call and exits. I'm not sure the random number is woking correctly, but I'm not sure -- I've tried outputting the value of 'character' after the random value is asigned to it - but nothing gets put on the screen. Any ideas?
Also, how is the program's logic - the if statements I mean. Is that set up to do what it should? Am I using the continue statement correctly - so I can ignore bad numbers and continuegetting the good ones?