Connecting Tech Pros Worldwide Help | Site Map

C:\KrugiKorobki.cpp|55|error: invalid operands of types `int' and `double' to binary

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: 4 Weeks Ago
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<TX/graphics.h>
  3. #include<time.h>
  4. // I need help!
  5. struct Krug{
  6.         double _x;
  7.         double _y;
  8.         double _skox;
  9.         double _skoy;
  10.         double _granx1;
  11.         double _grany1;
  12.         double _granx2;
  13.         double _grany2;
  14.         int _rad;
  15.         void init(double x,double y,double skox,double skoy,int rad,double granx1,double grany1,double granx2,double grany2);
  16.         void draw();
  17.         void dvig();
  18.     };
  19. struct Korobka{
  20.     double _granx1;
  21.     double _grany1;
  22.     double _granx2;
  23.     double _grany2;
  24.     int _kolvoprim;
  25.     Krug Circles[300];
  26.     void init(double granx1,double grany1,int granx2,int grany2,int kolvoprim);
  27.     void draw();
  28.     void start();
  29. };
  30. int main(){
  31.     txCreateWindow(1025,769);
  32.     txSetFillColor(txBLACK);
  33.     Korobka Yaschik;
  34.     Yaschik.init(100,100,801,601,5);
  35.     Yaschik.draw();
  36.     Yaschik.start();
  37.     return 0;
  38. }
  39. void Krug::init(double x,double y,double skox,double skoy,int rad,double granx1,double grany1,double granx2,double grany2){
  40.     _granx1=granx1;
  41.     _grany1=grany1;
  42.     _granx2=granx2;
  43.     _grany2=grany2;
  44.     _x=x;
  45.     _y=y;
  46.     _skox=skox;
  47.     _skoy=skoy;
  48.     _rad=rad;
  49. }
  50. void Korobka::init(double granx1,double grany1,int granx2,int grany2,int kolvoprim){
  51.     srand(time(0));
  52.     _granx1=granx1;
  53.     _grany1=grany1;
  54.     _granx2=granx2;
  55.     _grany2=grany2;
  56.     int rx=rand()%_granx2+_granx1;
  57.     int ry=rand()%_grany2+_grany1;
  58.     _kolvoprim=rand()%(kolvoprim+1);
  59.     for(int i = 0;i<_kolvoprim;i++){
  60.         Circles[i].init(rx,ry,rand()%10+1,rand()%10+1,rand()%10+5,_granx1,_grany1,_granx2,_grany2);
  61.     }
  62.  
  63. }
  64. void Korobka::draw(){
  65.     txRectangle(_granx1,_grany1,_granx2,_grany2);
  66. }
  67. void Korobka::start(){
  68.     while(1){
  69.         for(int i = 0;i<_kolvoprim;i++){
  70.             txLock();
  71.             Circles[i].dvig();
  72.             txUnlock();
  73.         }
  74.         txSleep(40);
  75.     }
  76. }
  77. void Krug::draw(){
  78.     txCircle(_x,_y,_rad);
  79. }
  80. void Krug::dvig(){
  81.     txSetColor(txBLACK);
  82.     Krug::draw();
  83.     if((_x+_rad<=_granx1)or(_x+_rad>=_granx2)){
  84.         _skox=-_skox;
  85.         Krug::init(_x+=_skox,_y+=_skoy,_skox,_skoy,_rad,_granx1,_grany1,_granx2,_grany2);
  86.     }
  87.     if((_y+_rad<=_grany1)or(_y+_rad>=_grany2)){
  88.         _skoy=-_skoy;
  89.         Krug::init(_x+=_skox,_y+=_skoy,_skox,_skoy,_rad,_granx1,_grany1,_granx2,_grany2);
  90.     }
  91.     else{
  92.         Krug::init(_x+=_skox,_y+=_skoy,_skox,_skoy,_rad,_granx1,_grany1,_granx2,_grany2);
  93.     }
  94.     txSetColor(txWHITE);
  95.     Krug::draw();
  96. }
  97.  
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 828
#2: 4 Weeks Ago

re: C:\KrugiKorobki.cpp|55|error: invalid operands of types `int' and `double' to binary


The error message in your title appears to identify line 55 as the source of the error. Does line 55 of your original source correspond to line 55 in the code you posted?
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 380
#3: 4 Weeks Ago

re: C:\KrugiKorobki.cpp|55|error: invalid operands of types `int' and `double' to binary


You can't use double ( _granx2 ) int modulo operation. ( btw , why
_gran** members are all double, but granx2 argument is int? )
Reply