Adding Numbers Generated By Random Number Generator in C

before I ask my question I would like to point out that I did look for the answers already, and I didn’t find what I was looking for.
Please bear in mind that I am a beginner in terms of programming, so please don’t assume that I know everything there is to know.
Right, to the question.
My question is : How do I add together numbers that are created by random number generator ? The difficulty that I have is the fact that the number of randomly generated numbers could be different every time the program is ran. To make it clearer, the amount of randomly generated numbers is dependent on the input from user, eg if the input is 9, the program will generate 9 random numbers. This makes it difficult for me to come up with the idea of how to add the random numbers together and display them.
Here is the source code from my program. I think it is important to mention that the random numbers change every time I run the program, which is how I want them to be ( I used srand() with time, and rand() ). Also, the problem that I have currently is that the program doubles the last randomly generated number instead of adding them all together.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int input;
scanf("%d", &input);
int i;
int roll;
int turn_total;
time_t t;
int sum;

srand((unsigned) time(&t));                                 // the seed for    the random number generator based on the current time


for( i = 0; i < input; i++)
{
roll = (rand() % 6 + 1);                                    // random number generator 
  sum = roll+roll;                                              // only dubbling the last roll for some reason = /
printf("You Rolled : %dn", roll);
}

    printf("The Total Turn Score is : %d", sum);

}

Any help, ideas or clues would be greatly appreciated.


Source: c#

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.