error: invalid operands to binary / (have 'char *' and 'int')|

+1 Kareem Almoubyed · November 20, 2015
hey bucky

in lesson 10  am trying to do this code

int girlsage = (AGE / 2 ) + 7;
  printf(" %s can date girls  older %d ",firstname , girlsage);
  return 0;
 and it keep says : error: invalid operands to binary / (have 'char *' and 'int')|

please help

Post a Reply


Oldest  Newest  Rating
0 c student · November 21, 2015
what is AGE?
0 Akhilesh Chobey · November 21, 2015
First define your variable AGE.And also your character (firstname).
That is: 
char[25] firstName;

int AGE, girlsAge;

scanf("Enter your name: %s", firstName);

scanf("Enter your age: %d", &AGE);

girlsAgeĀ = (AGE / 2 ) + 7;

printf(" %s can date girls older %d ",firstname , girlsage);

return 0;

I think this will work hopefully. :).
Is it understood?
0 Kareem Almoubyed · November 21, 2015
AGE #defined in handler 
0 Eryk Humberto Oliveira Alves · November 21, 2015
What is the type of AGE variable?

AGE is probably a char type. I'm pretty sure of that!

What you are trying to do is:

summing and dividing a text value.
It's like doing 

("55" / 2 ) + 7

Even if the string value represent a numerical value, that is impossible on C.
You can solve this simply by declaring AGE as int, or other numerical variable type (unsigned int, float, double, etc).
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator