Me and my friend need to make a license plate generator program as a final project for our c++ class. We're trying to make it so it outputs 6 random numbers and letters. I'm gonna try to make it pick 6 random numbers between 0 and 35. If it is a number between 0 and 9, it will show up as that number and if it is between 10 and 35, it will show up as a letter (10=A, 11=B, 35=Z). We can make it generate a number between 0 and 35, but don't know how to make it assign letters to the numbers it generates. So could anybody tell me how you would do that?

12 Years
Discussion Span
Last Post by arrr matey
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ( void )
   static const char value[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   int i;
   srand ( time ( 0 ) );
   for ( i = 0; i < 6; ++i )
      putchar ( value [ rand() % ( sizeof value - 1 ) ] );
   putchar ( '\n' );
   return 0;

And of course make sure you keep track of the numbers already generated so you don't end up handing out the same one twice...

I'd also be very careful turning in the solution shown above as it's not C++ at all (though a decent idea to get you started on your own work).

Remember people, we're not here to do peoples' homework for them, only to help with specific technical details...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.