fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct coor2d {
  7. float x;
  8. float y;
  9. };
  10.  
  11. // Inside a function
  12. int row = 5;
  13. int col = 5;
  14. float r_wide = 1.0/float(row);
  15. float r_high = 1.0/float(col);
  16.  
  17. vector<vector<coor2d> > grid;
  18. vector<coor2d> column;
  19. for(int cr = 0; cr < row; cr++) {
  20. for(int cc = 0; cr < col; cc++) {
  21. coor2d temp;
  22. temp.x = (float(cc) * r_wide) + (r_wide/2.0);
  23. temp.y = ((float(cr) * r_high) + (r_high/2.0) * -1.0);
  24. // Here the temp.y value is correct
  25. column.push_back(temp);
  26. // Here the temp.y value is incorrect
  27. }
  28. grid.push_back(column);
  29. }
  30.  
  31. int main() {
  32. // your code goes here
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:19:5: error: expected unqualified-id before ‘for’
     for(int cr = 0; cr < row; cr++) {
     ^
prog.cpp:19:21: error: ‘cr’ does not name a type
     for(int cr = 0; cr < row; cr++) {
                     ^
prog.cpp:19:31: error: ‘cr’ does not name a type
     for(int cr = 0; cr < row; cr++) {
                               ^
stdout
Standard output is empty