Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #define line "- - - - - - - - - - - - - - - - - - - - - -"
- typedef struct{
- int d,m,y;
- }date;
- typedef struct{
- int playerID;
- char name[20];
- char nationality[50];
- int age;
- int point;
- date updated;
- }player;
- int inputPlayers (player p[]) {
- int n=0;
- printf("Input Player Information\n");
- printf("Number of players: ");
- scanf("%d",&n);
- int i=0;
- while(i<n){
- printf("Player#%d",i+1);
- printf("\nPlayerID: ");
- scanf("%d",&p[i].playerID); fflush(stdin);
- printf("Name: ");
- scanf("%[^\n]s",p[i].name); fflush(stdin);
- printf("Nationality:");
- scanf("%[^\n]s",p[i].nationality); fflush(stdin);
- printf("Age: ");
- scanf("%d",&p[i].age); fflush(stdin);
- i++;
- }
- return n;
- }
- void updatePoints( player p[] , int n) {
- int round=0,i,j;
- player input;
- int newpoint;
- printf("\nUpdate Points of Players\n");
- printf("Number of players to update points: ");
- scanf("%d",&round);
- for(i=0;i<round;i++){
- printf("PlayerID: ");
- scanf("%d",&input.playerID);
- for(j=0;j<round;j++){
- if(input.playerID==p[j].playerID){
- printf("%s Current points = %d",p[j].name,p[j].point);
- printf("\nEnter new points: ");
- scanf("%d",&newpoint);
- p[j].point=newpoint;
- printf("Updated date (dd/mm/yyyy) : ");
- scanf("%d/%d/%d",&p[j].updated.d,&p[j].updated.m,&p[j].updated.y); fflush(stdin);
- }
- }
- }
- }
- void showPlayers (player p[],int n){
- printf("\nShow Player Information\n");
- printf("# PlayerlD Name Nationality Age Points Updated\n");
- printf(line);
- int i=0;
- while(i<n){
- printf("\n%d %d %s %s %d %d %d/%d/%d\n",i+1,p[i].playerID,p[i].name,p[i].nationality,p[i].age,p[i].point,p[i].updated.d,p[i].updated.m,p[i].updated.y);
- i++;
- }
- printf("\n");
- printf(line);
- }
- void ranking ( player p [] , int n){
- player rank[100];
- int point = p[0].point;
- int i=0,j=0;
- for(i=0;i<n;i++){
- if(point>p[i].point){
- point=p[i].point;
- rank[j]=p[i];
- j++;
- }
- }
- i=0;
- while(i<n){
- p[i]=rank[i];
- i++;
- }
- }
- int main(){
- player input[500];
- int n;
- n=inputPlayers(input);
- updatePoints (input,n);
- ranking (input,n);
- showPlayers (input,n);
- return 0;
- }
Add Comment
Please, Sign In to add comment