How to produce a random vehicle number (i.e RJ14CG3894) using rand() function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to produce a random vehicle number (i.e RJ14CG3894) using rand() function ?

It must consist of state code such as RJ or MP... or such followed by two alphabets and 4 digit Numbers. C++

12th Oct 2017, 9:24 AM
BHUWAN CHANDNA
3 Answers
+ 13
//========================== // Vehicle number generator // Done for: bhuwan Chandna // By : Babak Sheykhan //========================== #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(static_cast<size_t>(time(0))); string num = "xxyyxxyyyy"; // x: letter, y: number for (auto i = 0; i < num.length(); ++i) { if (num.at(i) == 'x') num.at(i) = 65 + rand() % (91 - 65); else num.at(i) = 48 + rand() % (58 - 48); } cout << num; } [https://code.sololearn.com/cM7oGReNXXqe]
12th Oct 2017, 10:04 AM
Babak
Babak - avatar
+ 13
Student must listen to his mentor more than ever. Thank you dear JPM7. @~)~~~~
12th Oct 2017, 1:36 PM
Babak
Babak - avatar
+ 7
What's the vehicle numbers' syntax?
12th Oct 2017, 9:26 AM
Dapper Mink
Dapper Mink - avatar