Connecting Tech Pros Worldwide Help | Site Map

Invalid operands to binary %

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 11th, 2008, 05:20 PM
Newbie
 
Join Date: Oct 2008
Posts: 16
Default Invalid operands to binary %

I'm a little confused about and error my compiler is giving me. The error message is "invalid operand to binary %." The compiler says that this code *avg = *range %10; Isn't this a valid binary operation in C?

Quote:
#include<stdio.h>
#include<stdlib.h>

#define Lower_Limit 0
#define Upper_Limit 100

void readScores( float *s1,float *s2, float *s3);

void determineAvg(float *s1,float *s2,float *s3, float *avg,int *range);

void printResults( float*avg);

int main(void){

float s1,s2,s3;
float A,B,C,D,F,avg;
int range;
readScores(&s1,&s2,&s3);
determineAvg(&s1,&s2,&s3,&avg,&range);
printResults(&avg);
return 0;




}

void readScores(float *s1, float *s2, float *s3){

printf("Enter three avgs to be calculated\n");
scanf("%f %f %f",s1,s2,s3);
}

void determineAvg(float *s1,float *s2,float *s3,float *avg,int *range)
{


*avg = (*s1+*s2+*s3)/3;
*range = (*avg)%10;
printf("%d",*range);


}

void printResults(float *avg){
printf("This is avg one %f\n",*avg);
return;
}
Reply
  #2  
Old October 11th, 2008, 05:59 PM
boxfish's Avatar
Expert
 
Join Date: Mar 2008
Location: California
Age: 14
Posts: 482
Default

The % operator can only be used with two int operands. Take a look at fmod from the math library.
Hope this helps.
Reply
  #3  
Old October 11th, 2008, 06:06 PM
Newbie
 
Join Date: Oct 2008
Posts: 16
Default

Thant did it! Thanks.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.