Was trying out a question that I saw online, the questions requires the user to input the number of time the random number will be generated and to count how many digit 1, digit 2, digit 3, are there int he generated number.
For example
Enter number of time to loop : 4
2241 1204 5532 8593
There are 8 digits 1, digit 2 and digit 3.
code:
int main()
{
int input;
int ranNum;
cout << "Enter the number of time to loop" << endl;
cin >> input;
srand(time(NULL));
int i = 0;
if (input < 0 || input > 50)
{
cout << "Invalid entry";
}
else
{
while(i++ < userInput)
{
ranNum = (rand() % 10000);
cout << ranNum<< " ";
}
}
return 0;
}
The questions stated that using a switch case will be easier to get it done. However, I am not too sure how can a switch case worked for this. Or, is there any other method that I can use?
I've completed the code for the first 2 part, which is requiring user to input number as well as generating the random number based on user input