![]() |
| | #1 |
| Registered User Join Date: Dec 2008
Posts: 7
| calling struct class within array i have a problem calling the struct class data from inside an array... error: C2664: 'DrukStudent' : cannot convert parameter 1 from 'int' to 'student'. Code: struct student
{
char naam[25];
struct datum gebdatum;
int resultaat;
};
void DrukStudent(struct student s)
{ /* naam en gebdatum (dd/mm/jjjj) afdrukken */
printf("%-10s",s.naam);
DrukDatum(s.gebdatum);
printf(" %d%%",s.resultaat);
}
double gemiddelde(struct student studentrij[ ], int aantal)
{
int i;
double result=0.0;
printf("\ntest array\n");
DrukStudent(studentrij[1].resultaat); /* here is the problem */
return result;
}
void main()
{
struct student studentrij[20] = {{"Anton",{25,4,1988}, 75},{"Bert",{24,5,1987}, 85},{"Chris",{23,6,1986}, 95},{"Dave",{22,7,1985}, 100}};
gemiddelde(studentrij,4);
}
And i cant seem to target them. I do not wish to use any pointers (!!) I know that my double gemiddelde(struct student studentrij[ ], int aantal) isnt looking like it is supposed to be, but right now i just want to target the class of resultaat and then i can move on. Thanks and happy new year |
| eastmus is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| DrukStudent expects a Student struct, but you pass an int. And main shall return int, always.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Registered User Join Date: Dec 2008
Posts: 7
| thanks Elysia, but i cant seem to figure out how to target 85 only. since Code: DrukStudent(studentrij[1]); Code: Bert 24/05/1987 85% |
| eastmus is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| So why are you printing the name and the date inside the function? Remove those printfs, change the function to take the score only and then just print the score.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #5 | |
| Registered User Join Date: Dec 2008
Posts: 7
| Quote:
Code: void DrukStudentGemiddelde(struct student s)
{ /* naam en gebdatum (dd/mm/jjjj) afdrukken */
printf(" %d",s.resultaat);
}
if there is rly no other way .... | |
| eastmus is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Except what you have is targeting the score by calling it, without any extra structs or arrays. How is it not what you want? |
| tabstop is offline | |
| | #7 |
| Registered User Join Date: Sep 2006
Posts: 2,508
| If I understand this correctly, I'd use a while loop to move the index array from 20(minus 1, so 19 really), back to the comma. The first number would be your one's column digit, so no problem. Your second number, if present, would need to be X 10 + one's column digit, for your total number. Or, another way, just let the index decrement back to the comma, then reverse it and read in the digits. If you read in 3 digits, you'll need to do this: Correct value = digit1 * 100 + digit2 * 10 + digit3 to get the value right. Code: i = 19;
while(structArray[i] != ',') //moving index back to the comma
--i;
for(j = 0; i < 20; i++) {
if(structArray[i] >= 0 && structArray[i] <= 9) {
numberchar[j++] = structArray[i];
}
}
for(i = j - 1; i < MaxChars (2 or 3); i++) {
temp = numberchar + '0'; //elevate char to a number
if(i = 3) //restore it's 10's place, again.
sum = temp * 100;
else if(i = 2)
sum += temp * 10;
else
sum += temp;
}
![]() I'm assuming 3 or fewer digits in this sample, and have not run this. It would be my starting place, however. |
| Adak is offline | |
![]() |
| Tags |
| array, struct |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with linked list sorting function | Jaggid1x | C Programming | 6 | 06-02-2009 02:14 AM |
| deriving classes | l2u | C++ Programming | 12 | 01-15-2007 05:01 PM |
| Array of struct pointers - Losing my mind | drucillica | C Programming | 5 | 11-12-2005 11:50 PM |
| Dikumud | maxorator | C++ Programming | 1 | 10-01-2005 06:39 AM |
| struct nested in a class - member variables initialization | Viana | C++ Programming | 4 | 12-12-2002 02:32 PM |