![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 5
Rep Power: 0
![]() |
pls check this for me...
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
#define runner 2
struct Athlete
{
char name[30];
float weight;
float height;
float timerecorded;
};
int i;
float name();
float sorting();
typedef Athlete ath;
ath runner [2];
main()
{
FILE *infile,*outfile;
infile=fopen("runner.dat","w");
if ((infile=fopen("runner.dat","w"))==NULL)
printf("file could not be opened\n");
else
{
name();
}
while (!feof(stdio))
{
fprintf(infile,"name");
fprintf(infile,"height");
fprintf(infile,"weight");
fprintf(infile,"time recorded");
for(i=0;i<runner;i++)
{
fprintf(infile,"\t#s""\t%.2f",runner[i].name,runner[i].height);
fprintf(infile,"\t%.2f""\t""\t%.2f""\n",runner[i].weight,runner[i].timerecorded);
}
fclose(infile);
if((outfile=fopen("runner.dat","r"))==NULL)
print("file could not be opened\n");
else
{
printf("file opened\n");
while(!feof(infile))
{
printf("athlete name: \t");
printf("weight : \t");
printf("height : \t");
printf("time recorded: \t");
}
for(i=0;i<runner;i++)
{
printf("\t%s""\t%.2f",runner[i].name,runner[i].height);
printf("\t%.2f""\t""\t%.2f""\n",runner[i].weight,runner[i].timerecorded);
}
fclose(outfile);
return 0;
}
float name()
{
for(i=0;i<num;i++)
{
printf("please enter runner NAME:");
scanf ("%s",&runner[i].name);
printf("please enter runner HEIGHT:");
scanf ("%f",&runner[i].height);
printf("please enter runner WEIGHT:");
scanf ("%f",runner[i].weight);
printf{"please enter runner TIMERECORDED:");
scanf ("%f",runner[i].timerecorded);
printf("\n");
}
sorting()
return (runner[i]);
}
float sorting()
{
int pass, temp;
for(pass=0;pass<runner-1;pass++)
{
for(i=pass+1;i<runner;++i)
if (runner[i].timerecorded>runner[pass].timerecorded)
{
temp=runner[pass].timerecorded;
runner[pass].timerecorded=runner[i].timerecorded;
runner[i].timerecorded=temp;
}
}
return(runner[i].timerecorded) ;
}i am facing problem to this assignment...i am newbie....pls check for me.. THX alot!!!!! |
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 3
![]() |
>i am facing problem to this assignment
Care to elaborate? kthnxbye
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
DaWei would know, but last I heard, his crystal ball was still in the shop for repairs.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
It's quite clear. Including stdio.h twice broke the tabbing mechanism.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 3
![]() |
>It's quite clear. Including stdio.h twice broke the tabbing mechanism.
*Gives DaWei a cookie*
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
Oh come on man...
Clean up your code a little, explain your problem, or at least show us some effort if you expect help. |
|
|
|
|
|
#7 | |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 372
Rep Power: 0
![]() |
Quote:
__________________
I am Addicted to Linux! |
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
![]() ![]() Ummmmmhmmmmmm. Da shin bone connectatada anklebone....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
#include<stdio.h>
#include<conio.h>
#define runner 2
struct Athlete
{
char name[30];
float weight;
float height;
float timerecorded;
};
int i;
float name();
float sorting();
typedef Athlete ath;
ath runner [2]; // <<<<<<<<<<<< this will be Athlete 2 [2] which is incorrect
int main()
{
FILE *infile, *outfile;
infile = fopen("runner.dat","w");
if ((infile=fopen("runner.dat","w")) == NULL)
printf("file could not be opened\n");
else
{
name();
}
while (!feof(stdio)) // <<<<<<<<<<<< where does this while end?
{
fprintf(infile,"name");
fprintf(infile,"height");
fprintf(infile,"weight");
fprintf(infile,"time recorded");
for(i=0;i<runner;i++)
{
fprintf(infile,"\t#s""\t%.2f",runner[i].name,runner[i].height);
fprintf(infile,"\t%.2f""\t""\t%.2f""\n",runner[i].weight,runner[i].timerecorded);
}
fclose(infile);
if((outfile=fopen("runner.dat","r")) == NULL)
print("file could not be opened\n");
else
{
printf("file opened\n");
while(!feof(infile))
{
printf("athlete name: \t");
printf("weight : \t");
printf("height : \t");
printf("time recorded: \t");
}
for(i=0;i<runner;i++)
{
printf("\t%s""\t%.2f",runner[i].name,runner[i].height);
printf("\t%.2f""\t""\t%.2f""\n",runner[i].weight,runner[i].timerecorded);
}
fclose(outfile);
return 0;
}
float name()
{
for(i=0;i<num;i++)
{
printf("please enter runner NAME:");
scanf ("%s",&runner[i].name);
printf("please enter runner HEIGHT:");
scanf ("%f",&runner[i].height);
printf("please enter runner WEIGHT:");
scanf ("%f",runner[i].weight);
printf{"please enter runner TIMERECORDED:");
scanf ("%f",runner[i].timerecorded);
printf("\n");
}
sorting() // <<<<<<<<<<<<<<<<< say what? missing a semicolon?
return (runner[i]);
}
float sorting()
{
int pass, temp;
for(pass=0;pass<runner-1;pass++)
{
for(i=pass+1;i<runner;++i)
if (runner[i].timerecorded>runner[pass].timerecorded)
{
temp=runner[pass].timerecorded;
runner[pass].timerecorded=runner[i].timerecorded;
runner[i].timerecorded=temp;
}
}
return(runner[i].timerecorded);
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2006
Posts: 5
Rep Power: 0
![]() |
i am soli for din explain my problem well....actually this is the assignment i am doing now.the assignment ask me to write a programme that can sort the runner's time which is including the name , height , and the weight of the runner.and this is the programme that i hd write yesterday.and i actually dunno wat is the problem of this programme.my teacher ask me to write the sorting function outside the main in order to sort the name(string) together.is this possible?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|