Whenever I enter a race time say 3.20 (for 3hrs 20 mins), when I go to produce the race report it brings up the time as 0.000000
What am I doing wrong?
Here is the code
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <float.h> typedef struct { char fname [15] ; char sname [35]; int age ; char category [2]; int number; float time; } competitor_details; //Global Variables FILE *compfile; competitor_details comp; int choice=0; //Declare Functions void menu (void); void entercompetitordetails(void); void producecompetitordetails(void); void enterracetimes(void); void produceracereport(void); int main(int argc, char *argv[]) { menu(); system("PAUSE"); return 0; } void menu() { while (choice !=9) { system("CLS"); printf(" +++++++++++++++++++++++++++++++++++++++++++\n"); printf(" + Competitor details +\n"); printf(" + +\n"); printf(" + [1] Enter competitor details +\n"); printf(" + [2] Produce competitor details +\n"); printf(" + [3] Enter race times +\n"); printf(" + [4] Produce race report +\n"); printf(" + [9] Exit +\n"); printf(" + +\n"); printf(" +++++++++++++++++++++++++++++++++++++++++++\n"); printf(" Enter Choice " ); scanf("%i",&choice); printf("\n"); switch (choice){ case 1:entercompetitordetails(); break; case 2:producecompetitordetails(); break; case 3:enterracetimes(); break; case 4:produceracereport(); break; case 9:printf("exit\n"); break; default : printf("It is one of the undefined values\n"); system("PAUSE"); break; } } } void entercompetitordetails(void) { system ("cls"); compfile=fopen("compfile.bin", "ab"); if (compfile ==0) {printf ("An error occurred opening file.\n"); } printf ("Please enter competitor number or 0 to quit\n"); scanf ("%i", &comp.number); while (comp.number != 0.) { printf(" Please enter first name \n"); scanf ("%s", &comp.fname); printf(" Please enter surname\n"); scanf ("%s", &comp.sname); printf(" Please enter age \n"); scanf ("%i", &comp.age); printf(" Please enter category (Juvenile J, standard S, Expert E} \n"); scanf ("%s", &comp.category); fwrite(&comp, sizeof(comp),1,compfile); printf ("Please enter competitor number or 0 to quit\n"); scanf ("%i", &comp.number); } fclose(compfile); system("PAUSE"); } /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void producecompetitordetails(void) { compfile = fopen("compfile.bin", "rb"); /* Open File */ if (compfile == 0) { printf ("An error occurred while opening the file.\a\n"); printf ("Please choose option 1.\n\n"); system("PAUSE"); }/*End of if statment*/ else { system ("cls"); /* Clear the Screen */ printf (" Competitor Details\n\n"); printf ("First Name\tSurname\tAge\tCategory\t Number\n"); while (!feof(compfile)) { fread(&comp, sizeof(comp),1,compfile); if(!feof(compfile)) printf ("%-20s\t%-20s\t%-2i\t%-3s\t%-3i\n", comp.fname, comp.sname, comp.age, comp.category, comp.number); }/*End of while*/ fclose (compfile);/*Close the file*/ system("PAUSE"); }} /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void enterracetimes(void) { int search_no; //local variable system ("cls"); compfile = fopen("compfile.bin","ab+"); if (compfile == 0) { printf ("File not opened\a\n"); printf ("Please choose option 1.\n\n "); system("PAUSE"); } else { printf ("Please enter competitor Number? "); scanf("%i", &search_no); while (!feof(compfile)) { fread(&comp, sizeof(comp),1,compfile); if (search_no == comp.number) { printf("Competitor is %s %s\n", comp.fname, comp.sname); printf ("Please enter competitors race time\n"); scanf ("%f", &comp.time); fwrite (&comp, sizeof(comp),1,compfile); break; } if (search_no!=comp.number) printf("competitor number is not Valid"); } fclose(compfile); system("PAUSE");} } /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void produceracereport(void) { compfile=fopen("compfile.bin", "rb"); if (compfile == 0) { printf ("An error occurred while opening the file.\a\n"); printf ("Please choose option 1.\n\n"); system("PAUSE"); }/*End of if statment*/ else { system ("cls"); /* Clear the Screen */ printf (" LIST OF COMPETITOR RACE TIMES ``\n\n"); printf ("COMPETITOR No.\tFIRST NAME \tSURNAME \tTIME\n\n"); while (!feof(compfile)) { fread(&comp, sizeof(comp),1,compfile); if(!feof(compfile)) printf ("%i \t%-15s\t %-10s\t %f\n", comp.number,comp.fname,comp.sname,comp.time); }/*End of while*/ } fclose (compfile);/*Close the file*/ system("PAUSE"); }



LinkBack URL
About LinkBacks



