Hi there y'all I have written a simple program that lets you roll a dice. So in one way I am passing this and in another I would like anyone capable of finding a bug, or check my code if I could have used less lines of code or Tell me if I have used bad programming practices. Thanks in advance! :)
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void Dice(int[],int); // dice function
int main(int argc, const char * argv[])
{
//Declaring variables for getting input, storing input in an array, and x for initializing the for loop which will initialize the array to be used
int iInput;
int diceArray[6];
int x;
//Getting input from user as to the number of dices he or she want rolled
printf("Enter the number of dice to roll(1-6): ");
scanf("%d", &iInput);
//for loop for initializing the array the array to be used
for( x = 0; x < 6; x++)
diceArray[x] = x;
Dice(&diceArray[x], iInput);//calling the array to caluculate the dice number and print out the stored dices
return 0;
}//end main
void Dice(int diceArray[6], int iInput)
{
//Initializing srand() inorder to user rand() to generate random numbers
srand((unsigned)time(NULL));
//Declaring the variable to be used
int x;
int diceroll;
//Variable diceroll is initialized to calculate the random dice numbers to be calculated
diceroll = (rand() % iInput) + 1;
if (iInput <= 6 && iInput > 0){//used if statement to make sure the user has only option to enter 1 - 6 as the different times to roll the dice
for ( x = 0; x < 6 ; x++ ){//for loop to initialize the array and store the value in the array
diceroll = (rand() % iInput) + 1;
diceArray[x] = diceroll;}
}//end of if
if (iInput <= 6 && iInput > 0){
for( x = 0; x < iInput; x++ )//for loop for printing out the stored dice values
printf("%d\n", diceArray[x]);
}//end of if
}// of Dice()