I am trying to find the sum of the scores by using arrays but i keep on coming u
ID: 3546688 • Letter: I
Question
I am trying to find the sum of the scores by using arrays but i keep on coming up with an error.
void printData(char name[][50], double dScore[], double eScore[], int max);
void finalScore(char names[][50], double dScore[], double eScore[], double finalScore[], int max);
int main()
{
int i;
double dScore[2], eScore[2], finalScore[2];
char names[2][50];
printf("This program will print out the resluts of the gymnast. ");
for(i=0;i<2;i++){
printf("Enter the Last Name, D-Score and E-Score of the competitor. ");
scanf("%s %lg %lg",names[i],&dScore[i],&eScore[i]);
if(dScore[i] < 0){break;}
}
printData(names, dScore, eScore, i);
finalScore(names, finalScore, i);
}
void printData(char names[][50], double dScore[], double eScore[], int max)
{
int j;
for(j=0;j<max;j++){
printf("Name: %s D-Score: %g E-Score; %g ", names[j],dScore[j],eScore[j]);
}
}
void finalScore(char names[][50], double dScore[], double eScore[], double finalScore[], int max)
{
int i;
for(i=0;i<max;i++){
finalScore[i] = dScore[i] + eScore[i];
printf("The Final Score is: ");
printf("Name: %s FinalScore: %g ", names[i],finalScore[i]);
}
}
Explanation / Answer
Itss because your function name you are trying to call is the same as a variable name you are using, rename the variable to finalScores[2] and your finalScore function asks for 5 parameters but you send 3 only with call finalScore(names, finalScore, i) also you don't need to pass the address of the array when you scanf, arrays automatically get passed by address.
#include <stdio.h>
#include <stdlib.h>
void printData(char name[][50], double dScore[], double eScore[], int max);
void finalScore(char names[][50], double dScore[], double eScore[], double finalScore[], int max);
int main()
{
int i;
double dScore[2], eScore[2], finalScores[2];
char names[2][50];
printf("This program will print out the resluts of the gymnast. ");
for(i=0;i<2;i++){
printf("Enter the Last Name, D-Score and E-Score of the competitor. ");
scanf("%s %lg %lg",names[i],dScore[i],eScore[i]);
if(dScore[i] < 0){break;}
}
printData(names, dScore, eScore, i);
finalScore(names, dScore, eScore, finalScores, i);
}
void printData(char names[][50], double dScore[], double eScore[], int max)
{
int j;
for(j=0;j<max;j++){
printf("Name: %s D-Score: %g E-Score; %g ", names[j],dScore[j],eScore[j]);
}
}
void finalScore(char names[][50], double dScore[], double eScore[], double finalScore[], int max)
{
int i;
for(i=0;i<max;i++){
finalScore[i] = dScore[i] + eScore[i];
printf("The Final Score is: ");
printf("Name: %s FinalScore: %g ", names[i],finalScore[i]);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.