Ask coding questions

← Back to all posts
What should I add to be able to choose the times that I want the code to choose a random number?
GrabielPerez

What should I add to be able to choose the times that I want the code to choose a random number?

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{

}

Answered by Baconman321 [earned 5 cycles]
View Answer
Voters
GrabielPerez
Comments
hotnewtop
Baconman321

Are you saying that you want to have the program generate a random number every so often?

GrabielPerez

@Baconman321 no, I want that the program ask me how many numbers I want to generate before the program choose a random number

Baconman321

@GrabielPerez You would have to use std::cin to get your input, then use that as the iteration count.

As for generating multiple random numbers in a loop, srand is seeded by time and therefore will only generate one random number.

Use this answer for a workaround.

GrabielPerez

@Baconman321 thanks!

Baconman321