循环的字母和数字

时间:2015-02-04 20:06:27

标签: c for-loop nested-loops

我试图遍历一堆字母然后然后循环播放数字,但是,我遇到了问题。

问题是这些字母不会停止循环。

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>

int inuti(double x, double y, double x1, double y1, double x2, double y2) {
  int x_inuti;
  int y_inuti;

  if (x1 < x2)
    x_inuti = x > x1 && x < x2;
  else
    x_inuti = x > x2 && x < x1;
  if (y1 < y2)
    y_inuti = y > y1 && y < y2;
  else
    y_inuti = y > y2 && y < y1;
  return x_inuti && y_inuti;
}

int main(void) {
  double x, y, x1, y1, x2, y2;
  char text_x, text_y, text_x1, text_y1, text_x2, text_y2;
  int resultat;
  int i, i2, i3, i4, i5, i6;

  char tecken[] = "ab";// cdefgABCDEFG. + -";
  char teckenback[] = "-+";// .GFEDXBAgfedcba";
  int max;
  int maxback;
  max = strlen(tecken);
  maxback = strlen(teckenback);

      //This is the number loop     
  for (x = 0; x <= 3; x+=0.1) {
    for (y = 0; y <= 3; y+=0.1) {
      for (x1 = 0; x1 <= 3; x1+=0.1) {
        for (y1 = 0; y1 <= 3; y1+=0.1) {
          for (x2 = 0; x2 <= 3; x2+=0.1) {
            for (y2 = 0; y2 <= 3; y2 += 0.1){

              printf("punktens x-varde: %.1f \n", x);


              printf("punktens y-varde: %.1f \n", y);

              printf("\n");

              printf("Ena hornets x-varde: %.1f \n", x1);


              printf("Ena hornets y-varde: %.1f \n", y1);

              printf("\n");

              printf("Andra hornets x-varde %.1f \n", x2);


              printf("Andra hornets y-varde %.1f \n", y2);

              printf("\n");
              resultat = inuti(x, y, x1, y1, x2, y2);


              if (resultat == 1)
                printf("Punkten var inuti rektangeln.\n");
              else
                printf("Punkten var utanfor rektangeln.\n");

              printf("\n");
              printf("\n");

            //This is the letter loop. The problem is that it never stops here. But if commenting away the number loop, this runs and stops without a problem
              for (i = 0; i < max; i++) {
                for (i2 = 0; i2 < maxback; i2++) {
                  for (i3 = 0; i3< max; i3++) {
                    for (i4 = 0; i4 < maxback; i4++) {
                      for (i5 = 0; i5 < max; i5++) {
                        for (i6 = 0; i6 < maxback; i6++) {

                          text_x = tecken[i];
                          text_y = teckenback[i2];
                          text_x1 = tecken[i3];
                          text_y1 = teckenback[i4];
                          text_x2 = tecken[i5];
                          text_y2 = teckenback[i6];

                          printf("punktens x-varde: %c \n", text_x);


                          printf("punktens y-varde: %c \n", text_y);

                          printf("\n");

                          printf("Ena hornets x-varde: %c \n", text_x1);


                          printf("Ena hornets y-varde: %c \n", text_y1);

                          printf("\n");

                          printf("Andra hornets x-varde %c \n", text_x2);


                          printf("Andra hornets y-varde %c \n", text_y2);

                          printf("\n");

                          printf("##### Endast nummer tillatet! #####");
                          printf("\n");
                          printf("\n");

                        }
                      }
                    }
                  }
                }
              }       
            }
          }
        }
      }
    }
  }

  getchar();
  return 0;
}

当我评论数字循环时,字母循环完美地工作。但不知何故,他们无法一起工作。有谁知道问题是什么?

0 个答案:

没有答案