c++ - How can I define RAND_MAX -
how create program generates ten random numbers 1 -> rand_max?
rand_max must number input user.
int main() { using namespace std; int x; int y; random: { x = rand(); cout << x << endl; } y = y + 1; if (y == 10) { return 0; } goto random; }
something like:
int main() { int randmax; cin >> randmax; (int y = 0; y < 10; y++) { int x = rand() % randmax; // range = [0, randmax) cout << x+1 << endl; // range = [1, randmax] } } oh, , try avoid goto (at least in opinion). here two questions it.
Comments
Post a Comment