hi, I'm newbie here, this is my first thread, and my first post,
NICE TO MEET YOU GUYS!
Firstly, I want to apologize if my english is not easy to understand (I'm Indonesian who study in US).
ok, I have a problem with printing the problem, i have search many thread but I got no any answer.
look at this code,
Code:
void PrintOut (char First[], char Last[], int Birth, int Swimming, int Tennis,
int Horse, int Craft, int Total )
{
printf("%0s %0s %6d %2d %2d %2d %2d %2d\n",
First, Last, Birth, Swimming, Tennis, Horse, Craft, Total);
}
if I input the data like this,
Code:
Enter the number of people attend: 3
Enter the first name: benedict
Enter the last name: tobias
Enter the birth date: 190990
Enter the swimming skill score: 10
Enter the tennis skill score: 9
Enter the horsemanship skill score: 9
Enter the crafts skill score: 0
Enter the first name: ben
Enter the last name: tob
Enter the birth date: 209900
Enter the swimming skill score: 1
Enter the tennis skill score: 1
Enter the horsemanship skill score: 1
Enter the crafts skill score: 1
Enter the first name: tobias
Enter the last name: ben
Enter the birth date: 102939
Enter the swimming skill score: 10
Enter the tennis skill score: 10
Enter the horsemanship skill score: 10
Enter the crafts skill score: 10
the result after I input the data is printed like this
Code:
First Name Last Name Birth Swimming Tennis Horse Craft Total Score
benedict tobias 190990 10 9 9 0 28
ben tob 209900 1 1 1 1 4
tobias ben 102939 10 10 10 10 40
instead of,
Code:
First Name Last Name Birth Swimming Tennis Horse Craft Total Score
benedict tobias 190990 10 9 9 0 28
ben tob 209900 1 1 1 1 4
tobias ben 102939 10 10 10 10 40
my question is, how to print a neat table like i want? I have trouble about space, if I put only 3 character in "Last Name", all of the entire score will move..
This is the entire code:
Code:
#include <stdio.h>
int PeopleAttend ();
int Compute (int a, int b, int c, int d);
void GetInput (char *First[], char *Last[], int *Birth);
void GetScore (int *Swimming, int *Tennis, int *Horse, int *Craft);
void PrintOut (char First[], char Last[], int Birth, int Swimming, int Tennis,
int Horse, int Craft, int Total );
void Heading ();
void Ending ();
int main()
{
char FirstName [16][20];
char LastName [16][20];
int BirthDate [20];
int Swimming [20];
int Tennis [20];
int Horse [20];
int Craft [20];
int People;
int TotalScore[20];
int PeopleCounter;
PeopleCounter = PeopleAttend();
for (People = 0; People < PeopleCounter; People++)
{
GetInput(&FirstName[People], &LastName[People], &BirthDate[People]);
GetScore(&Swimming[People], &Tennis[People], &Horse[People], &Craft[People]);
TotalScore[People] = Compute(Swimming[People], Tennis[People], Horse[People],
Craft[People]);
}
Heading();
for (People = 0; People < PeopleCounter; People++)
{
PrintOut (FirstName[People], LastName[People], BirthDate[People], Swimming[People],
Tennis[People], Horse[People], Craft[People], TotalScore[People]);
}
Ending();
}
int PeopleAttend()
{
int x;
printf("Enter the number of people attend: ");
scanf (" %d", &x);
return x;
}
int Compute (int a, int b, int c, int d)
{
int x;
x = a + b + c + d;
return x;
}
void GetInput (char *First[], char *Last[], int *Birth)
{
printf("Enter the first name: ");
scanf (" %s", First);
printf("Enter the last name: ");
scanf (" %s", Last);
printf("Enter the birth date: ");
scanf (" %d", Birth);
}
void GetScore (int *Swimming, int *Tennis, int *Horse, int *Craft)
{
printf("Enter the swimming skill score: ");
scanf (" %d", Swimming);
printf("Enter the tennis skill score: ");
scanf (" %d", Tennis);
printf("Enter the horsemanship skill score: ");
scanf (" %d", Horse);
printf("Enter the crafts skill score: ");
scanf (" %d", Craft);
}
void Heading ()
{
printf("\t\t\t\tSUMMER REPORT CAMPERR\n\n");
printf("First Name Last Name Birth Swimming Tennis Horse Craft Total Score\n");
}
void PrintOut (char First[], char Last[], int Birth, int Swimming, int Tennis,
int Horse, int Craft, int Total )
{
printf("%0s %0s %6d %2d %2d %2d %2d %2d\n",
First, Last, Birth, Swimming, Tennis, Horse, Craft, Total);
}
void Ending ()
{
printf("---------------------------------------------------------------------------");
}
Thank You.