er....too large for simple process?

This is a discussion on er....too large for simple process? within the C Programming forums, part of the General Programming Boards category; Just curious if ths program is over large for a program that really doesn't so much besides roll diceand kind ...

  1. #1
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77

    Question er....too large for simple process?

    Just curious if ths program is over large for a program that really doesn't so much besides roll diceand kind of draw them....anyone...? (i'm new to this stuff)


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <time.h>
    
    void main()
    {
    	char Dice1[]="\0\0\0\0\0\0\0";
    	char Dice2[]="\0\0\0\0\0\0\0";
    	int R1=0,R2=0,A1=0,A2=0,x=5,y=219,total;
    	srand((unsigned)time(NULL)); 
    
    	printf("\n\n\t\t*********************");
    	printf("\n\t\t*  The Dice Roller  *");
    	printf("\n\t\t*********************\n\n");
    
    	printf("\tRolling...  [.....]\b\b\b\b\b\b");
    	while (x>0)  {
    		Sleep(220);
    		printf("%c",y);
    		x--;   }
    
    	R1 = rand() % 6 + 1;
    	R2 = rand() % 6 + 1;
    
    	total=(R1+R2);
    
    	x=0; y=0;
    	A1=R1; A2=R2;
    
    	while (R1>=0)  {
    		Dice1[x] = '*';   
    		x++;
    		R1--; }
    
    	while (R2>=0)  {
    		Dice2[y] = '*';
    		y++; 
    		R2--; }
    
    	if ((A1==1) || (A1==3) || (A1==5))  {
    	
    	printf("\n\n\t\t\t Dice 1: %i \n",A1);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice1[3],Dice1[5]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice1[6],Dice1[1],Dice1[7]);   
    	printf("\t\t\t| %c %c  |\n",Dice1[4],Dice1[2]);   
    	printf("\t\t\t ------\n");       }
    
    	if ((A1==2) || (A1==4) || (A1==6))  {
    	
    	printf("\n\n\t\t\t Dice 1: %i \n",A1);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice1[1],Dice1[4]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice1[5],Dice1[7],Dice1[6]);   
    	printf("\t\t\t| %c %c  |\n",Dice1[3],Dice1[2]);   
    	printf("\t\t\t ------\n");       }
    	
    	if ((A2==1) || (A2==3) || (A2==5))  {
    	
    	printf("\n\t\t\t Dice 2: %i\n",A2);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice2[3],Dice2[5]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice2[6],Dice2[1],Dice2[7]);   
    	printf("\t\t\t| %c %c  |\n",Dice2[4],Dice2[2]);   
    	printf("\t\t\t ------\n");      }
    
    	if ((A2==2) || (A2==4) || (A2==6))  {
    	
    	printf("\n\t\t\t Dice 2: %i \n",A2);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice2[1],Dice2[4]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice2[5],Dice2[7],Dice2[6]);   
    	printf("\t\t\t| %c %c  |\n",Dice2[3],Dice2[2]);   
    	printf("\t\t\t ------\n\n\t");       }
    
    	printf("\tDICE TOTAL:  %i",total);
    	printf("\n\n\t\tPlease Press Any Key...");
    	getchar();
    }

  2. #2
    FCF
    FCF is offline
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40
    Hi, could u please show your problem more detail ?

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <time.h>
    
    /* Usually main is of type int */
    void main()
    {
    	char Dice1[]="\0\0\0\0\0\0\0";
    	char Dice2[]="\0\0\0\0\0\0\0";
    	int R1=0,R2=0,A1=0,A2=0,x=5,y=219,total;
    	srand((unsigned)time(NULL)); 
    
    	printf("\n\n\t\t*********************");
    	printf("\n\t\t*  The Dice Roller  *");
    	printf("\n\t\t*********************\n\n");
    
    	printf("\tRolling...  [.....]\b\b\b\b\b\b");
    	while (x>0)  {
    		Sleep(220);
    		printf("%c",y);
    		x--;   }
    
    	R1 = rand() % 6 + 1;
    	R2 = rand() % 6 + 1;
    
    	total=(R1+R2);
    
    	x=0; y=0;
    	A1=R1; A2=R2;
    
    	while (R1>=0)  {
    		Dice1[x] = '*';   
    		x++;
    		R1--; }
    
    	while (R2>=0)  {
    		Dice2[y] = '*';
    		y++; 
    		R2--; }
    
                    /* I would pass the printing with printf's in a 
                             function. It would make the program a little
                             shorter in code and a bit more clearer. */ 
    	if ((A1==1) || (A1==3) || (A1==5))  {
    	
    	printf("\n\n\t\t\t Dice 1: %i \n",A1);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice1[3],Dice1[5]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice1[6],Dice1[1],Dice1[7]);   
    	printf("\t\t\t| %c %c  |\n",Dice1[4],Dice1[2]);   
    	printf("\t\t\t ------\n");       }
    
    	if ((A1==2) || (A1==4) || (A1==6))  {
    	
    	printf("\n\n\t\t\t Dice 1: %i \n",A1);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice1[1],Dice1[4]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice1[5],Dice1[7],Dice1[6]);   
    	printf("\t\t\t| %c %c  |\n",Dice1[3],Dice1[2]);   
    	printf("\t\t\t ------\n");       }
    	
    	if ((A2==1) || (A2==3) || (A2==5))  {
    	
    	printf("\n\t\t\t Dice 2: %i\n",A2);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice2[3],Dice2[5]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice2[6],Dice2[1],Dice2[7]);   
    	printf("\t\t\t| %c %c  |\n",Dice2[4],Dice2[2]);   
    	printf("\t\t\t ------\n");      }
    
    	if ((A2==2) || (A2==4) || (A2==6))  {
    	
    	printf("\n\t\t\t Dice 2: %i \n",A2);
    	printf("\t\t\t ------\n");
    	printf("\t\t\t| %c %c  |\n",Dice2[1],Dice2[4]);  
    	printf("\t\t\t| %c%c%c  |\n",Dice2[5],Dice2[7],Dice2[6]);   
    	printf("\t\t\t| %c %c  |\n",Dice2[3],Dice2[2]);   
    	printf("\t\t\t ------\n\n\t");       }
    
    	printf("\tDICE TOTAL:  %i",total);
    	printf("\n\n\t\tPlease Press Any Key...");
    	getchar();
    
        /* Since usually main is of type int, a int-value should
                 be returned. */
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 11:05 AM
  2. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 02:14 PM
  3. Replies: 3
    Last Post: 10-15-2008, 10:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 02:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 08:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21