Click here to Skip to main content
15,896,402 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include "stdafx.h"
#include<stdlib.h>
#include<time.h>

 int main()
{
    int x;
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
        x =  rand() % 6 +1 ;  

    printf("random number %d \n ", x);

    return 0;
}
Posted

1 solution

You already have: main is a function.
if you are trying to move
C#
x =  rand() % 6 +1 ;
into a separate function, then try this:
C++
int GetRandomNumber()
   {
   return rand() % 6 + 1;
   }
int main()
   {
   int x;
   time_t seconds;
   time(&seconds);
   srand((unsigned int) seconds);
   x =  GetRandomNumber();
   printf("random number %d \n ", x);
   return 0;
   }
 
Share this answer
 
Comments
Member 12202551 24-Jan-16 3:47am    
Thanks a lot for your help ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900