首页 > 解决方案 > 程序没有使用 switch 语句,而是直接关闭

问题描述

以下代码:它为我的字符值/类型命中 scanf 语句的实例所有地狱都崩溃了程序立即关闭,没有错误代码,什么也没有。我觉得我正在失去它。我似乎无法弄清楚问题可能是什么,我没有任何随机中断语句或任何应该关闭代码的东西。请帮忙

#include <stdio.h>


int main() {

    
    char type;
    int value=0;

    printf("Enter Shape Choice: 1 Inverted triangle, 2 Square, 3 Slope, 4 Diamond with Marked Edges\n");
    scanf_s("%d", &value);

    printf("Enter Charachter to draw with:\n");
    scanf_s("%c", &type);

        int count = 0;
        int count2 = 0;
        int firstcounter = 0;
        int value2 = 0;
        if (value == 1) {
            printf("please enter how many lines you would like:");
            scanf_s("%d", &value2);
        }


    switch (value) {
        case(1):
            while (firstcounter <= value2) {
                for (int i = value2; i > firstcounter; i--) {
                    printf("*");
                }
                printf("\n");
                firstcounter++;


            }
            break;

        case(2):
            for (int i = 0; i < 5; i++) {

                for (int j = 0; j < 5; j++) {

                    printf("%c", type);

                }
                printf("\n");
            }
            ;
            break;

        case(3):

            for (int i = 0; i < 5; i++) {

                count2 = 5;
                while (count2 > i) {
                    printf(" ");
                    count2--;
                }

                count = 0;
                printf("%c", type);

                while (count <= i - 1) {
                    printf("*");
                    count++;
                }
                printf("\n");

            }
            ;
            break;


        case(4):


            printf("    %c", type);
            int seccount = 1;
            for (int i = 0; i <= 4; i++) {

                int firstcount = 1;
                int thirdcount = 10;

                printf("\n");


                if (i < 3) {
                    for (int k = 3; k > i; k--) {
                        printf(" ");
                    }

                    printf("%c", type);

                    while (firstcount <= seccount) {
                        printf("*");
                        firstcount++;;
                    }

                    printf("%c", type);

                    seccount = seccount + 2;
                }


                if (i >= 3) {

                    for (int k = 1; k < i; k++) {
                        printf(" ");
                    }
                    printf("%c", type);

                    while (thirdcount > seccount) {
                        printf("*");
                        thirdcount--;
                    }
                    seccount = seccount + 2;
                    printf("%c", type);

                }
            }
            printf("\n    %c", type);
            ;
            break;

        }

}
        
        
    

        
    

标签: ccharscanf

解决方案


推荐阅读