Home › Forums › C Programming › invalid operands of types `float’ and `int’ to bin
- This topic has 2 replies, 3 voices, and was last updated 17 years, 2 months ago by S.Thananchayan.
- AuthorPosts
- October 27, 2007 at 3:59 pm #2020chuckyParticipant
I’m a beginner, so not too harsh on the criticism. Ok, so I have the code
1234567891011<br />void circle()<br />{<br />int r;<br />double Area;<br />cout << "Enter the radius: ";<br />cin >> r;<br />Area = PI * r^2;<br />cout << "The area is " << Area << "n";<br />main();<br />}and i try to compile it and i get an error saying “38 invalid operands of types
float’ and
int’ to binary `operator^'”. What should I do? - October 28, 2007 at 6:25 pm #3260msaqibParticipant
Hello
Well there is a sligh problem with your code. You are using ^ as a power operator but there is no such operator which performs the power operations. This operator (^) is a bitwiase operator to calculate XOR.To calculate the power you can use pow(double x, double y) function. It will calculate x power y.
Also make sure you include math.h header in your program as pow function is defined is this header file.
So your function should look like1234567891011void circle()<br />{<br />double r=0.0;<br />double m=2.0;<br />double area=1;<br />printf("enter area");<br />scanf("%lf",&r);<br />area =PI* pow(r,m);<br />printf("%lf",area);<br />getch();<br />} - October 29, 2007 at 10:33 am #3261S.ThananchayanParticipant1234567891011121314#include <iostream><br />using namespace std;<br />int main()<br />{<br />float pi = 3.14;<br />int r;<br />double area;<br />cout << "Enter the radius: ";<br />cin >> r;<br />area = r * r * pi;<br />cout << "The area is " << area << "n";<br />return(0);<br /><br />} </iostream>
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.