# Getting an error with array or pointer type!

This topic is 4945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

/* this program sort numbers, note: not names of the game players;
even though each player has their own name, this program focuses
more on sorting each players' scores alone with their desire name,
to see what game player got the highest scores in the game of skating */

#include <stdio.h>  // basic input and output functions

// function procedure to get basic data of player
// return void to return nothing, remember astronauts program
// problem was this one getting error returning a value.
void getdata(char skaters[][15], double scores[][6]);
void averages(char skaters[][15], double scores[][6], double average[]);
void bubblesort(char skaters[][15], double average[], char *pointer[], double *decimal[]);

// our main program global function
int main()
{

// initialize all the necessary variables needed
// major variables are: skaters[][], scores[][],
// average[][], *pointer[][] and *decimal[];
char skaters[11][15]={0}, *pointer[11];
double scores[11][6]={0}, average[11]={0}, *decimal[11];

// getdata function procedure to prompt the user
// for the name of each skaters' scores
getdata(skaters,scores);

// average function procedure to average all the
// six scores from all 10 skaters
averages(skaters,scores,average);

// bubblesort function procedure to sort all the
// six scores by averages in descending order
bubblesort(skaters,average,pointer,decimal);

// return 0 if compile successfully
return 0;
}

// getdata function procedure for getting each skaters'
// name and six scores.
void getdata(char skaters[][15], double scores[][6])
{

// create a variable that would count the number of times
// the for...loop should pass. In our case 10 names and
// 6 scores for each skater.
int count=0;

for(count=1;count<11;count++)
{
printf("\nEnter the names of the #%d skaters: ",count);
scanf("%s",skaters[count]);
printf("\nEnter the scores of %s: ",skaters[count]);
scanf("%f %f %f %f %f %f",&scores[count][1], &scores[count][2],
&scores[count][3], &scores[count][4], &scores[count][5],
&scores[count][6]);
}
}

// average function procedure to get the skater's
// average score out of all six scores.
void averages(char skaters[][15], double scores[][6], double average[])
{

// to total the average of the six scores first we eliminate
// the high and low scores by finding out which is the highest and lowest
// score of the skater.
int count=0,j=0;
double total={0};
for(count=1;count<11;count++)
{

// here we initialize the high score and low scores by the first number
// of that the skater has.
double high=scores[count][1];
double low=scores[count][1];

// initialize for...loop to determine high and low scores
// this is a simple formula or algorithm.
for(j=2;j<=6;j++)
{

// compare second number of the skater by the varible low or first score.
// If the second score is less than first, assign the second
// score to the variable low.  Loop...Until you get to the
// lowest score possible.
if(scores[count][j] < low)
{
low = scores[count][j];
}

// if second score is higher than the first score then initialize
// second score to the variable high, keep looping through all
// six scores to determine which one is the highest score.
if(scores[count][j] > high)
{
high = scores[count][j];
}
}

// add all six scores of the skater.
for(j=1;j<=6;j++)
{
total = total + scores[count][j];
}

// eliminate the high score and the lowest score.
total = total - low - high;

// get the average of all the six scores by dividing
// the total scores by 4, because we have eliminated
// two of them, the highest and lowest scores.
average[count] = (total / 4);

}
}

void bubblesort (char skaters[][15], double average[], char *pointer[11], double *decimal[11])
{
int flag=1, count=0;
int final = 10 - 1;

for(count=1;count<11;count++)
{
pointer[count] = &skaters[count][0];
printf("%s\n",pointer[count]);
}

for(count=1;count<11;count++)
{
decimal[count] = &average[count][0];
printf("%f",decimal[count]);
}

}