I’m new to this programming world so I’m sorry if I’m asking a stupid question. I have a problem trying to get a variable output from a random number generator input. What I’m trying to do is take the output from the number generator and have that determine the out come. My number generator goes from 1-12, what I want it to do is have the output vary so that if an output is between 1-4 it says no, and if it is between 5-8 it say maybe, and 9-12 is yes. I got the number generator working fine, but I can’t get the code right to make it determine the proper outputs. Is there a special magic word I should be using? My “if” statements always come back with errors that I don’t know how to fix. I’m sure I’m trying to do something that is way beyond my knowledge level and I shouldn’t even be trying this, but I want to learn as much as possible.
That was my problem. I changed the else and everthing is fine. I've also stripped the line var from my code. Thank you very much. If you don't mind me asking, but what would I need to add if I wanted to have the generator produce multiple outputs and give me the responce to all of those outputs? i.e. 12,2,6,9,1.....yes,no,maybe,yes,no
OK, I'm going crazy! I've tried this with the while loop (which causes the whole thing to blow up). All I want is for it to give me the answer for each output.
int random_integer;
for(int index = 0; index < 11; index++){
random_integer = (rand() % 12)+1;
cout << random_integer << endl;
}
if (random_integer < 5){
cout << "no\n";
}
else if (random_integer < 9) {
cout << "Maybe \n";
}
else
cout << "yes \n";
}
what I get is 11 variable numbers and the answer (yes, no, or maybe) for the last output. Shouldn't it tell me what each of the 11 outputs are? what am I missing?