#include <stdlib.h>    // needed for randomize() and random() functions
#include <iostream.h>  // needed for cin and cout
#include <conio.h>     // needed for getch() function

/* prints a random number in the range 1 to n */
void main(void)
{
    int n = 0, result = 0;

    cout << "Enter a value for n: ";
    cin >> n;
    cout << "Random number in the range (1 to " << n << "):";
    randomize();
    while (result == 0)
    {
    	result = random(n+1); // random generation
                            // of a number in the range
      							 // 0 to n
    }
    cout << " " << result;
    getch();
 }

