Problems producing report in C

Race Times not produced properly

Page 1 of 1

3 Replies - 452 Views - Last Post: 23 May 2009 - 07:32 AM Rate Topic: -----

#1 loopymoo26  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 11-February 09

Problems producing report in C

Posted 22 May 2009 - 03:35 AM

I am trying to get my program to produce a race report after the race times have been entered. If I enter 3.20 for say (3hrs 20 mins) when I produce the report it produces 0.000000

What am I doing wrong

#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");

}

This post has been edited by loopymoo26: 22 May 2009 - 04:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Problems producing report in C

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Problems producing report in C

Posted 22 May 2009 - 03:55 AM

You need to go through your code and fix the indentation and brace "}{" placement.

The compiler is giving this:
dic.c:206: error: nested functions are disabled, use -fnested-functions to re-enable
dic.c:234: error: syntax error at end of input

and you have this in your code
"}}"

Good signs that you need to give your code a good scrub and find alignment problems.
Was This Post Helpful? 0
  • +
  • -

#3 loopymoo26  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 11-February 09

Re: Problems producing report in C

Posted 23 May 2009 - 06:36 AM

cheers for the advice, but Ive sorted the problem now.
Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Problems producing report in C

Posted 23 May 2009 - 07:32 AM

Excellent news.
Glad to hear it's all fixed now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1