Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2006, 8:33 AM   #1
optimistic87
Newbie
 
Join Date: Mar 2006
Posts: 5
Rep Power: 0 optimistic87 is on a distinguished road
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!!!!!
optimistic87 is offline   Reply With Quote
Old Jun 29th, 2006, 8:35 AM   #2
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 3 Narue is on a distinguished road
>i am facing problem to this assignment
Care to elaborate? kthnxbye
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old Jun 29th, 2006, 12:21 PM   #3
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
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
Prm753 is offline   Reply With Quote
Old Jun 29th, 2006, 12:55 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jun 29th, 2006, 2:27 PM   #5
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 3 Narue is on a distinguished road
>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.
Narue is offline   Reply With Quote
Old Jun 29th, 2006, 3:16 PM   #6
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
Oh come on man...

Clean up your code a little, explain your problem, or at least show us some effort if you expect help.
ivan is offline   Reply With Quote
Old Jun 29th, 2006, 3:40 PM   #7
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 371
Rep Power: 0 King is an unknown quantity at this point
Quote:
Originally Posted by ivan
Oh come on man...

Clean up your code a little, explain your problem, or at least show us some effort if you expect help.
Well he is newb, so he may not know how to clean up his code... but he definitely should have gave more of an explanation.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Jun 29th, 2006, 5:09 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road


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
DaWei is offline   Reply With Quote
Old Jun 29th, 2006, 5:37 PM   #9
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by DaWei

Ummmmmhmmmmmm. Da shin bone connectatada anklebone....
Exactly, that means:
#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
nnxion is offline   Reply With Quote
Old Jun 30th, 2006, 7:43 AM   #10
optimistic87
Newbie
 
Join Date: Mar 2006
Posts: 5
Rep Power: 0 optimistic87 is on a distinguished road
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?
optimistic87 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC