I haev to make this work!

This is a discussion on I haev to make this work! within the C Programming forums, part of the General Programming Boards category; I need to make this work without global varibles! Can someone please HELP! Code: //David Thurlby //CIS 150 //Assignment 6-7 ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    Angry I haev to make this work!

    I need to make this work without global varibles! Can someone please HELP!

    Code:
    //David Thurlby
    //CIS 150
    //Assignment 6-7
    
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <conio.h>
    
    #define SIZE 20
    
    int getRand();
    int sortA();
    int sortD();
    int printSorted();
    
    
    int main()
    {
    	//declared
    	int a[SIZE];
    	int b[SIZE];
    	int count;//in functions
    	int swap1,swap2;//in main
    
      
    	printf("Getting Random Numbers\n");
    	getRand();
    	for(count=0;count<SIZE;count++)
        printf("%4d",a[count]);
      
    	sortA(a[SIZE]);
    	sortD(b[SIZE]);
      
    	printf("\n\n");
    	printf("Swaps for A= %d\n",swap1);
    	printf("Swaps for D= %d\n",swap2);
    	printf("Press Any Key To Continue");
    	getch();
    	system("cls");
    	printSorted();
    	return 0;
    }
    
    
    
    int getRand(a[SIZE],count)//getting Random num
    {	
      
      srand(time(NULL));
      
      for(count=0;count<=SIZE;count++)
      {
        a[count]=b[count]=rand()%100;
      }	
      return 0;
    }
    
    
    int sortA(a[SIZE],count,swap1)//sort Acending
    { 
      for(swap1=1;swap1<=SIZE-1;swap1++)
      {
        for(count=0;count<=SIZE-2;count++)
        {
          if(a[count]>a[count+1])
          {
            hold = a[count];
            a[count]=a[count+1];
            a[count+1] = hold;
          }
        }
      }
      return 0;	
    }
    
    
    int sortD(b[SIZE],count,hold,swap2)//sort Descending
    { 
      for(swap1=1;swap1<=SIZE-1;swap1++)
      {
        for(count=0;count<=SIZE-2;count++)
        {
          if(b[count]<b[count+1])
          {
            hold = b[count];
            b[count]=b[count+1];
            b[count+1] = hold;
          }
        }
      }
      return 0;	
    }
    
    
    int printSorted(a[SIZE],b[SIZE],count)//printing
    {
      for(count=0;count<SIZE;count++)
        printf("%d\n",a[count]);
      getch();
      system("cls");
      for(count=0;count<SIZE;count++)
        printf("%d\n",b[count]);
      
      return 0;
    }
    thank you and i appreciate your help

    Code tags fixed by Hammer
    Dave

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Eh? What global variables?

    And the end-code-tag is [/code], not [end code].
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    Angry I cant get this to work!

    I had global varibles in this and i took them out and stuck them into main. It says i have 12 errors in it for some reason and i dont get why. Can you help?

    Code:
    //David Thurlby
    //CIS 150
    //Assignment 6-7
    
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <conio.h>
    
    #define SIZE 20
    
    int getRand();
    int sortA();
    int sortD();
    int printSorted();
    
    
    int main()
    {
    	//declared
    	int a[SIZE];
    	int b[SIZE];
    	int count;//in functions
    	int swap1,swap2;//in main
    
      
    	printf("Getting Random Numbers\n");
    	getRand();
    	for(count=0;count<SIZE;count++)
        printf("%4d",a[count]);
      
    	sortA(a[SIZE]);
    	sortD(b[SIZE]);
      
    	printf("\n\n");
    	printf("Swaps for A= %d\n",swap1);
    	printf("Swaps for D= %d\n",swap2);
    	printf("Press Any Key To Continue");
    	getch();
    	system("cls");
    	printSorted();
    	return 0;
    }
    
    
    
    int getRand(a[SIZE],count)//getting Random num
    {	
      
      srand(time(NULL));
      
      for(count=0;count<=SIZE;count++)
      {
        a[count]=b[count]=rand()%100;
      }	
      return 0;
    }
    
    
    int sortA(a[SIZE],count,swap1)//sort Acending
    { 
      for(swap1=1;swap1<=SIZE-1;swap1++)
      {
        for(count=0;count<=SIZE-2;count++)
        {
          if(a[count]>a[count+1])
          {
            hold = a[count];
            a[count]=a[count+1];
            a[count+1] = hold;
          }
        }
      }
      return 0;	
    }
    
    
    int sortD(b[SIZE],count,hold,swap2)//sort Descending
    { 
      for(swap1=1;swap1<=SIZE-1;swap1++)
      {
        for(count=0;count<=SIZE-2;count++)
        {
          if(b[count]<b[count+1])
          {
            hold = b[count];
            b[count]=b[count+1];
            b[count+1] = hold;
          }
        }
      }
      return 0;	
    }
    
    
    int printSorted(a[SIZE],b[SIZE],count)//printing
    {
      for(count=0;count<SIZE;count++)
        printf("%d\n",a[count]);
      getch();
      system("cls");
      for(count=0;count<SIZE;count++)
        printf("%d\n",b[count]);
      
      return 0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    Talking THANX!

    Thanx man, i totally appreciate it. Ive been workin on this stuff and i jus dont get what im doin. Ya helped me alot.
    Dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  4. cant make it work
    By papous27 in forum Linux Programming
    Replies: 0
    Last Post: 03-05-2002, 08:49 PM
  5. how to make files
    By quiksilver9531 in forum C++ Programming
    Replies: 6
    Last Post: 02-22-2002, 05:44 PM

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