Thread: Storing Variables that come from a random number generator

  1. #1
    Registered User cgn38's Avatar
    Join Date
    Jan 2004
    Posts
    4

    Question Storing Variables that come from a random number generator

    I am trying to write a program to add, subtract, multiply and divde Fractions. This is just the add part.
    User inputs number of problems and number of digits in the numerator and denominator.
    My Questions is how do you store the results of the random number generator?

    Code:
    /* Program Title: Fractions Add
    Programmer: Charles Krolick
    Date: 12/16/2003*/
    
    #include <stdio.h>
    #include <math.h>
    #include <system.h>
    #include <stdlib.h>
    #include <time.h>
    struct add1 {int num [10];} addnum;
    struct add2 {int dem [10];} adddem;
    
    	int main(void)
    {
    	int a;//digits in numerator
    	int b;//digits in demoninator
    	int c;//number of problems
    	int j;
    	int LIMIT;
    
    	//int p;
    	
    	printf("All answers must be reduced to its simplest form.\n");
    	printf("How many Problems would you like? \n");
    		scanf("%i",&c);		
    	
    	
    	printf("Maximum digits in the numerator? \n"); 	//limit a to 3 digits max
    		scanf("%i",&a);
    		
    		if (a==2)
    		{
    			LIMIT=99;
    		}
    		if (a==3)
    		{
    			LIMIT=999;
    		}
    
    
    		srand((unsigned)time(NULL));  	//need 1 a for every c
    	 	for (j = 0; j < c; j++)
    		{
    		int i = rand() % LIMIT;
    		//printf("The random number is %d\n", i);
    		}
    		
    	printf("Maximum digits in the denominator? \n");  	//limit b to 3 digits
    		scanf("%i",&b);
    		
    		if (b==2)
    		{
    			LIMIT=99;
    		}
    		if (b==3)
    		{	LIMIT=999;
    		}
    	
    	 	
    		srand((unsigned)time(NULL));  	//need 1 b for every c
    		for (j = 0; j < c; j++)
    		{
    		int i = rand() % LIMIT;
    		printf("The random number is %d\n", i);
    		}
    		
    		
    	
    // 				
    //   n1  n2  n3  n4......
    //  --- --- --- ---
    //   d1  d2  d3  d4......	
    		
    	
    
    
    return 0;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >how do you store the results of the random number generator?
    Most people prefer some form of array, but you can use whatever data structure suits you.
    My best code is written with the delete key.

  3. #3
    Registered User cgn38's Avatar
    Join Date
    Jan 2004
    Posts
    4
    OK
    I forgot to add that to my question. should I use an array or a struct. Thanks for the advise Prelude.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. help with random number generator
    By Brimak86 in forum C Programming
    Replies: 3
    Last Post: 01-12-2008, 09:37 PM
  3. Storing random number in array(sequential search & bubble sort)
    By dukethacore in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2005, 08:28 AM
  4. Storing random number in array(sequential search & bubble sort)
    By dukethacore in forum C++ Programming
    Replies: 1
    Last Post: 07-20-2005, 07:23 AM
  5. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 05:26 AM