hello. im having a trouble in this program of mine. since im new in the field of advanced turbo c, that's why, i can't think of any possible answer in that illegal pointer error. help me, pretty please?:unsure: here's the code, i need to use, here is the array, as well as the pointers. Code: //scoring system of a pageant #include<stdio.h> #include<conio.h> void main() { int no[7]; //number of the candidate float sd[7]; //speech delivery 50% float sp[7]; //stage presence 20% float pe[7]; //poise and elegance 20% float oa[7]; //overall appearance 10% float total=0; int i; int *a,*b,*c,*d,*e; for(i=0;i<7;i++) { printf("\n speech delivery : %d",i+1); scanf("%d",&sd[i]); printf("\n poise and elegance : %d",i+1); scanf("%d",&pe[i]); printf("\n stage presence : %d",i+1); scanf("%d",&sp[i]); printf("\n overall appearance : %d",i+1); scanf("%d",&oa[i]); } clrscr(); printf("\n NO.\tspeechDelivery\tPoiseandElegance\tstagePresence\tOverallAppearance\ttotal"); for(i=0;i<7;i++) { //speech delivery computation sd=(sd/100)*50; //poise and elegance computation pe=(sd/100)*20; //stage presence computation sp=(sd/100)*20; //overall appearance oa=(sd/100)*10; total=(sd+pe+sp+oa)/4; a=&sd[i]; b=&pe[i]; c=&sp[i]; d=&oa[i]; e=&total; printf("\n\n[%d]\t%f\t%f\t%f\t%f\t%f",i+1,*a,*b,*c,*d,*e); } getch(); } there. illegal use of pointer in the line of Code: //speech delivery computation sd=(sd/100)*50; //poise and elegance computation pe=(sd/100)*20; //stage presence computation sp=(sd/100)*20; //overall appearance oa=(sd/100)*10; and another problem is the invalid poiter addition in the line of : Code: total=(sd+pe+sp+oa)/4; can you guys help me? thank you !
You've got a few of things going on. Below, you're using the wrong format specifier in scanf. Code: for(i=0;i<7;i++) { printf("\n speech delivery : %d",i+1); //scanf("%d",&sd[i]); wrong format specifier scanf("%f", &sd[i]); // same for other float arrays } In the code below, you can't do that with arrays. You need a pointer or use [] for each element. The math here also yields integer division, so you're results may be off. Promote the division to floating point by using sd / 100.0 or whatever. Code: for(i = 0; i < 7; ++i) { // sd = (sd / 100) * 50; invalid indexing sd[i] = (sd[i] / 100.0f) * 50.0f; // same for other arrays } You've got the same problem with the line below; that is, you can't manipulate the arrays like that. You're going to have to loop through each of the four arrays to find total. Code: total=(sd+pe+sp+oa)/4; Below, you're using int pointers on floats and also using the wrong format specifier for ints in the printf; those should be "%d" and not "%f". Is there a purpose/requirement for doing that? Code: a=&sd[i]; b=&pe[i]; c=&sp[i]; d=&oa[i]; e=&total; printf("\n\n[%d]\t%f\t%f\t%f\t%f\t%f",i+1,*a,*b,*c,*d,*e);
yay. THANK YOU. I guess I still have a lot more to learn about C prog, I hope I can manage to learn that much )) thanks anyway!!!