die Frage war:wie dieses Strukturarray an die Funktion übergeben wird, was ist falsch mit meinem Code?
Ein Kurs durch das folgende gekennzeichnet:
Course Name: cName (string of 32 characters)
Course Number: cNumber (integer)
Number of Students enrolled: nStudents (integer)
Level: Level (character: ‘G’ for graduate, ‘U’ for undergraduate)
Grades: sGrades (array of 40 integers)
Define a structure, called CourseType, which includes the above properties.
In the main program: use the structure you defined to declare an array of 5 courses, and store in this array the information below about these courses (the information below specify the course name, number, number of students, and level:
“Introduction to Programming”, 230, 37, ‘U’
“Computer Networks”, 450, 44, ‘U’
“Data Structures & Algorithms”, 330, 38, ‘U’
“Distributed Databases”, 630, 18, ‘G’
“Mobile Ad hoc Networks”, 656, 34, ‘G’
die Qualitäten betrifft, für jeden Kurs, erzeugen so viele Zufallswerte wie es Studenten sind und speichert sie in dem Array von Noten (sGrades). Diese Werte sollten zwischen 50 und 100.
Write a function DisplayCourseStatistics that takes as input a course structure, and computes the average grade, minimum grade, and maximum grade in the course. After computing these three values, the function displays them.
In the main program: after defining the structure and the five courses in part c, and populating these courses with the data (including the grades), ask the user to specify the course number. Then call the function DisplayCourseStatistics and pass it the corresponding course structure in order for it to display the grade statistics (average, minimum, and maximum).
Der Code i schrieb ich noch Fehler = haben [
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct CourseType CourseType;
struct CourseType
{
char cName[32];
int cNumber;
int nStudents;
char Level;
int sGrades[44];
};
void DisplayCourseStatistics(CourseType course[],int n);
int main()
{
int i;
CourseType course[5];
strcpy(course[0].cName,"Introduction to Programming");
course[0].cNumber=230;
course[0].nStudents=37;
course[0].Level='U';
for(i=0;i<37;i++)
{
course[0].sGrades[i]=50+rand()%(50);
}
strcpy(course[1].cName,"Computer Networks");
course[1].cNumber=450;
course[1].nStudents=44;
course[1].Level='U';
for(i=0;i<44;i++)
{
course[1].sGrades[i]=50+rand()%(50);
}
strcpy(course[2].cName,"Data Structures & Algorithms");
course[2].cNumber=330;
course[2].nStudents=38;
course[2].Level='U';
for(i=0;i<38;i++)
{
course[2].sGrades[i]=50+rand()%(50);
}
strcpy(course[03].cName,"Distributed Databases");
course[3].cNumber=630;
course[3].nStudents=18;
course[3].Level='G';
for(i=0;i<18;i++)
{
course[3].sGrades[i]=50+rand()%(50);
}
strcpy(course[4].cName,"Mobile Ad hoc Networks");
course[4].cNumber=656;
course[4].nStudents=34;
course[4].Level='G';
for(i=0;i<34;i++)
{
course[4].sGrades[i]=50+rand()%(50);
}
int n;
printf("enter the course number that you'd like to display its stat");
scanf("%d",&n);
DisplayCourseStatistics(CourseType course[n],n);
}
void DisplayCourseStatistics(CourseType course[n],int n)
{
int average_grade;
int minimum_grade;
int maximum_grade;
int sum=0;
int i;
for(i=0;i<course[n].nStudents;i++)
{
sum+=course[n].sGrades[i];
if(course[n].sGrades[i]>course[n].sGrades[i+1])
{
minimum_grade=course[n].sGrades[i+1];
maximum_grade=course[n].sGrades[i];
}
else if(course[n].sGrades[i]<course[n].sGrades[i+1])
{
minimum_grade=course[n].sGrades[i];
maximum_grade=course[n].sGrades[i+1];
}
}
printf("The Average Grade is %d\nThe Maximum Grade is %d\nThe Minimum Grade is %d\n",average_grade=(sum/course[n].nStudents),maximum_grade,minimum_grade);
}
was falsch ist und was kann ich tun Dank! !!
für die Kommentare es soll 40 sein, aber ich benutze 44 Ursache in einem Kurs ist die Anzahl der Studenten 44, die> 40 so ist und für die Fehler eigentlich ich usinf Codepad bin ich also es nicht sicher, sagt, dass Fehler: zu wenig Argumente
Was _spezifisches_ Problem haben Sie? Was funktioniert, was ist nicht und was verstehst du nicht über die Fehler? – Mat
Und die Fehler sind? – Bart
Welche Fehler/Warnmeldungen gibt der Compiler? Wenn keine, was produziert der Code auf welchen Input und was erwartet ihr? – Attila