Can someone help me with random chooser project

I am trying to do a simple project.
The program should first randomly choose a car for you. e.g: Lambo, Toyota, Mazda.
Then it should randomly choose a country to live in. e.g: Russia, Italy, India...
Then it should randomly choose a job. e.g: Doctor, Policeman, Business man...
And so on, but i don't know how to make a random chooser(not random choose for a number but a variable like words).
So can someone help me and give me a couple of codes and show them to me how this kind of system works.(Am using c++)
could you show us what you did/tried???

this might help

http://www.cplusplus.com/reference/cstdlib/srand/

all the best!
I haven't done anything, i have no idea where to start from.
do you know how to use cout and cin???
yes ofcourse but i don't know where to start from. like in this type of project, i don't know anything.
Normally you would store your data in an array like this:
 
const std::string CarNames[] = {"Lambo", "Mazda", "Toyota"};

To choose a random car you can use the rand() function like this:
std::string RandomCar = CarNames[rand() % 3];
and for details of cars you could use a struct (or class)....
It's saying 'rand' was not declared in this scope ?! What do i do exactly
use the stdlib and time header file for rand function

though I would recommend srand

http://www.cplusplus.com/reference/cstdlib/srand/
Last edited on
To give you an idea (C++ 11 or later):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <random> //C++ 11
#include <string>

//Function Prototype.
int randomChoice(int min, int max);

int main()
{
    std::string numbers[] = { "Zero", "One", "Two", "Three", "Four", "Five",
	   "Six", "Seven", "Eight", "Nine" };
    const int maxLoops{ 25 };
    const int minRandNum{ 0 };
    const int maxRandNum{ 9 };

    for (int count = 0; count < maxLoops; count++)
    {
	   std::string randomNumbers = numbers[randomChoice(minRandNum, maxRandNum)];
	   std::cout << randomNumbers << std::endl;
    }
	   
    return 0;
}

int randomChoice(int min, int max)
{
    std::mt19937 generator(std::random_device{}());
    std::uniform_int_distribution<int> distributionToss(min, max); // Set the numbers for int.
    const int randNumber = distributionToss(generator);

    return randNumber;

}
Topic archived. No new replies allowed.