嗨!我的代码在这里有问题。当我尝试访问这个scruct数组时,它不会让我访问实际的数组空间 i ,而是它一遍又一遍地给我相同的数组值,直到它完成。你们有没有看到错误?这是一个相对较短的,除了我的代码,函数的名称是正确的,不要担心。但是,每当我尝试使用draw_boxes时,它只会给我box []的位置0,这是数组框[]中的第一个;没有了,从而没有给出我想要的东西。请记住,我是第一学期的IT学生,之前没有使用c ++编程的经验。对你来说可能显而易见的事情对我来说不会那么明显。
#include <iostream>
#define CIMGGIP_MAIN
#include "CImgGIP05.h"
using namespace std;
struct Box
{
int x;
int y;
int delta_y;
};
const int box_max = 10, box_size = 40;
void draw_boxes(Box boxes[])
{
white_background();
for (int i = 0; i < box_max; i++)
{
gip_draw_rectangle(boxes[i].x, boxes[i].y, box_size, box_size,
blue);
/* don't mind this, it's something we had in our given header file.
This line is correct*/
}
}
int main() {
Box boxes[box_max] = { 0 };
for (int i = 0; i < box_max; i++)
{
boxes[i].x = i * (box_size + 20) + 10;
boxes[i].y = 0;
boxes[i].delta_y = random(10, 30);
}
draw_boxes(boxes);
return 0;
}
当我使用draw_boxes()函数时,我希望它循环遍历我的数组[],而不只是使用它。
我得到的结果是语法错误。它只会使用一个box []的空格,即使我给它其他空格的索引,所以它只适用于一组值。
提前感谢您的帮助!
答案 0 :(得分:1)
您的代码没问题,但您的逻辑可能不对。
你的函数gip_draw_rectangle可能是:
variable "google_kubernetes_username" {
default = "<YOUR_USERNAME>"
}
variable "google_kubernetes_password" {
default = "<YOUR_PASSWORD>"
}
你想要的地方gip_draw_rectangle(x1,y1,x2,y2,color);
你的盒子只是重叠。最后一个是全部。
尝试:
x2 = x1 + width; and y2 = y1 + height;