Can Some-one check if i have made any mistakes!!

This is a discussion on Can Some-one check if i have made any mistakes!! within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> struct comp_detail { char name[20][30]; int faults[20],number; float etime[20]; float otime[20]; }; int main () { int ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    Question Can Some-one check if i have made any mistakes!!

    Code:
    #include <stdio.h>
    
    struct comp_detail
    {
    	char name[20][30];
    	int faults[20],number;
    	float etime[20];
    	float otime[20];
    };
    
    
    int main ()
    {
    
    int opselect;
    	printf("\n***************************************");
    	printf("\n* Please enter a selection:           *");
    	printf("\n* Press 1 to enter data               *");
    	printf("\n* Press 2 to print out data           *");
    	printf("\n* Press 3 to calculate data           *");
    	printf("\n* Press 4 to sort data                *");
    	printf("\n* Press 5 to save data                *");
      printf("\n* Press 6 to quit program             *");
    	printf("\n***************************************\n");
    	scanf("%d", &opselect);
    
    	switch (opselect)
    	{
    		case 1:
                    read_data();
    	              break;
    		case 2: 
                    print_data();
    		            break;
    		case 3:
                    find_data();
    		            break;
    	                case 4:
                    sort_data();
                                                break;
    		case 5:
    	save_data();
                                                break;
                                    case 6:
    		            break;
    	}
    
    
    
    struct comp_detail comp;
    struct comp_detail read_data();
    
    
     int number;
     do{
    	  printf("\nHow many competitors are there? [up to 20]");
    	  scanf("%d", &number);
         }
     while ((number < 0 ) || (number > 20));
    
     int i = 0; 
     do{
        printf ("\nCompetitor #");
        comp = read_data();
        i++;
       }
     while ( i < number );
    
    
    return(0);
    }
    
    
    
    
    void read_data (struct comp_detail * pt_comp_detail)
    { 
     struct comp_detail new;
     printf("\nEnter Competitors Name:   "); 	/*prompts user to input name */
     gets(name);				/*calls name */
     printf("\nEnter Elapsed Time:  ");		/*prompts user to enter elapsed time */
     scanf("%.2f", &new.etime);		/*scans into time, to two decimal places */
     printf("\nEnter The number of faults:   ");	/*prompts user to enter in number of faults */
     scanf("%d", &new.faults);		/*scans contents into faults */ 
     return(new);
    }
    
    void print_data (comp_detail * pt_comp_detail)
    {
     printf ("\nThe Competitor Named:   ");
     printf ("\nElement1:  %d",pt_matrix->tl);
     
     printf ("\nName                  Elapsed Time    Faults");
     printf ("\n--------------------------------------------");
    
    for (i = 0; i < j; i++)
    	{
     printf ("\n");
     printf ("%8.2f         &d",pt_comp_detail->etime[i],pt_comp_detail->faults[i]);
     return;
      }
    }
    
    float find_data(int faults[], float etime[])
    
    for (i=0; i<= 19; i++)
    {
    int otime[i] = (4 * faults[i]) + etime[i];
    
    return (otime[])
    }
    
    sort_data(float otime[])
    {
    for (i=0; i<= 19; i++)
    {
     int ipos[20];
     float stime =9999999999999999999;
     
     if (comp_detail.otime[i] < stime)
      posi[i] = i;
     }
    
    for (i=0; i<= 19; i++)
    {
     printf("&c",&comp_detail.name[ipos]);
     printf("\n%.2f",&comp_detail.otime[ipos]);
    }
    
    
    
    int save_data(int i, int comp_detail[])
    {
    FILE * newfile;
    newfile = fopen("Competition.txt", "w");
    
    for(i = 1; i <= 12; ++i)
    {
    fprintf(newfile,"\n%d %d", &i, &comp_detail.name[i], &comp_detail.otime[i], &comp_detail.faults[i], &comp_detail.etime[i]);
    }
    
    fclose(newfile);
    return (0);
    }
    Please remember http://cboard.cprogramming.com/misc....bbcode#buttons next time - Salem

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>float stime =9999999999999999999;
    Just to show you what can happen here:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      float stime = 9999999999999999999;
      printf ("%f\n", stime);
      return(0);
    }
    
    /* output on my compiler:
    
    9999999980506447872.000000
    
    */
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check application visibility
    By 3saul in forum Linux Programming
    Replies: 2
    Last Post: 02-13-2006, 04:13 PM
  2. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 05:44 PM
  3. MFC: How do you check if a directory exists before creating?
    By BrianK in forum Windows Programming
    Replies: 5
    Last Post: 07-06-2004, 01:09 AM
  4. check if txt file
    By Boomba in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2003, 07:43 PM
  5. writing/reading from file produces double results.
    By stumon in forum C Programming
    Replies: 4
    Last Post: 03-20-2003, 03:01 PM

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