Hey can you help me with this program? I cant get it to work it will not display the final part.
You can e-mail me on [email protected].
/*Robert Parker*/
/*29/01/02*/
/*Berner Mountain Bike Club Marathon*/
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
typedef struct
{
int age;
char forname[30];
char surname[30];
char cat[1];
float time;
}competitor_structure;
typedef struct
{
int last_no;
int age;
char forname[30];
char surname[30];
char cat[1];
float time;
}last_no_structure;
FILE *competitor_file;
FILE *last_no_file;
int choice;
competitor_structure competitor_array[1];
last_no_structure last_no_array[1];
int num_records = 1;
int num_records1 = 1;
int competitor_no;
float average_time=0;
float average_jev=0;
float average_fun=0;
float average_ex=0;
float numof;
float jevnum=0;
float exnum=0;
float funum=0;
float jevtime=0;
float extime=0;
float funtime=0;
time_t now;
void intro();
void menu();
void add();
void report();
void competitortime();
void race_report();
void end();
int main()
{
intro();
do
{
menu();
}while (choice!=5);
system("cls");
printf("\n\n\n\nThank you for using this program designed and implemented by Robert Parker\n\n\n\n");
printf("\n\n\t\tPlease Have A Nice Day\n\n");
system("pause");
}
void intro()
{
printf("\n\n\n\n\t\tWelcome to the Berner Mountain Bike Marathon Race Program");
printf("\n\n\n\n\n\t\tProgram created by Robert Parker\n\n");
printf("\n\t\t");
system("PAUSE");
}
void menu()
{
system("cls");
printf("\n\n\n\n\t\t\t\t\tMAIN MENU\n");
printf("\n\n\t\t1 - Add Competitor to file");
printf("\n\n\t\t2 - Produce Competitors Report");
printf("\n\n\t\t3 - Enter Finished Results");
printf("\n\n\t\t4 - Produce Finished Report");
printf("\n\n\t\t5 - Exit Program");
printf("\n\n\t\tPlease Enter Choice ");
scanf("%i", &choice);
fflush(stdin);
switch(choice)
{
case 1: add() ;break;
case 2: report() ;break;
case 3: competitortime() ;break;
case 4: race_report() ;break;
case 5: break;
default:
{
printf("\n\n\t\t Not A Valid Choice (1 to 5 Only): ");
system("pause");
menu();
}
}
}
void add()
{
competitor_file = fopen("c:\\competitors.bin","ab");
system("cls");
printf("\n\n\t\tAdd New Records To File");
printf("\n\tForname ? ");
fflush(stdin);
gets(competitor_array[num_records].forname);
printf("\n\tSurname ? ");
fflush(stdin);
gets(competitor_array[num_records].surname);
printf("\n\tAge ? (18 to 99 only) ");
scanf("%i", &competitor_array[num_records].age);
printf("\n\tCatagory ? J(Juvenille) S(Standard) E(Expert) ");
fflush(stdin);
gets(competitor_array[num_records].cat);
fwrite(&competitor_array[num_records],sizeof(competitor_structure),1,competitor_file);
fclose(competitor_file);
}
void report()
{
/* open file for reading */
competitor_file = fopen("c:\\competitors.bin","rb");
/* clear the screen */
system("cls");
/* display headings */
printf("\n\t\t\t\tCompetitor Reports");
printf("\n\n\n ID NO\tFORNAME\t\t\t\tSURNAME\t\t\tAGE\tCATAGORY");
/* read first record into array */
num_records=0;
fread(&competitor_array[1],sizeof(competitor_structure),1,competitor_file);
/* read rest of records from file and place in array of records */
while(!feof(competitor_file))
{
/* display record */
printf("\n%6i %-30s %-30s %4i %-1s\n\t",num_records,competitor_array[1].forname,competitor_array[1].surname,
competitor_array[1].age,competitor_array[1].cat);
fflush(stdin);
num_records++;
fread(&competitor_array[1],sizeof(competitor_structure),1,competitor_file);
}/* end of while */
/* pause to allow user to view book details */
system("pause");
/* close file */
fclose(competitor_file);
}/* end of book_details */
void competitortime()
{
/*This is the file paths*/
competitor_file = fopen("c:\\competitors.bin","rb");
last_no_file = fopen("c:\\competitortime.bin","ab");
/*This is reading records from the racedetails file*/
fread(&competitor_array[1],sizeof(competitor_structure),1,competitor_file);
/*This is not the end of file marker*/
while (!feof(competitor_file))
{ system("cls");
printf("\n\tForename\t\t Surname\n");
printf("\n\t%-30s\t%-20s\n",competitor_array[1].forname, competitor_array[1].surname);
printf("Please enter race time for this Competitor\n");
scanf("%f",&last_no_array[1].time);
/*This is saving the files to the time_file*/
fwrite(&last_no_array[1], sizeof(last_no_structure),1,last_no_file);
/*This is writing to file*/
num_records++;
fread(&competitor_array[1], sizeof(competitor_structure),1,competitor_file);
/*This is reading to file*/
}
fclose(competitor_file);
fclose(last_no_file);
/*This is closing both files*/
system("pause");
}
void race_report()
{
last_no_file = fopen("c:\\competitortime.bin","rb");
competitor_file = fopen("c:\\competitors.bin","rb");
/*This is opening the time_file*/
system("cls");
printf("\n\nThis is a full Competitor report with race times\n");
fread(&last_no_array[1], sizeof(last_no_structure),1,last_no_file);
float total_time=0;
/*This is for storing the total time*/
while (!feof(last_no_file))
{
printf("\n%6i %-20s %-30s %.2f\n\n", competitor_array[1].forname,
competitor_array[1].surname,
last_no_array[1].time);
/*This is calalatuing the total time*/
total_time=total_time+last_no_array[1].time;
if ((last_no_array[1].cat[0]=='J')||(last_no_array[1].cat[0]=='j'))
{
jevtime = jevtime + (last_no_array[1].time);
jevnum+1;
}
if ((last_no_array[1].cat[0]=='E')||(last_no_array[1].cat[0]=='e'))
{
extime = extime + (last_no_array[1].time);
exnum+1;
}
if ((last_no_array[1].cat[0]=='S')||(last_no_array[1].cat[0]=='s'))
{
funtime = funtime + (last_no_array[1].time);
funum+1;
}
fread(&last_no_array[1],sizeof(last_no_structure),1,last_no_file);
/*This is reading the file*/
}
average_time=0;
/*This calaulating the average time*/
printf("\n total_time = %.2f com_num = %i",&total_time,&num_records);
printf("\n funtime = %.2f funum = %i",&funtime,&funum);
printf("\n extime = %.2f exnum = %i",&extime,&exnum);
printf("\n jevtime = %.2f jevnum = %i",&jevtime,&jevnum);
average_time = total_time/num_records;
average_fun = funtime/funum;
average_ex = extime/exnum;
average_jev = jevtime/jevnum;
printf("\n\n\n\n");
printf("The average time is %.2f\n\n",&average_time);
printf("the average J time was %.2f\n\n\n",&average_jev);
printf("the average S time was %.2f\n\n\n",&average_fun);
printf("the average E time was %.2f\n\n\n",&average_ex);
fclose(last_no_file);
fclose(competitor_file);
system("pause");
system("cls");
}