0

Following code: The instance it hits the scanf statement for my character value/type all hell breaks loose program instantly shuts down, no error codes, no nothing. I feel like I'm loosing it. I cannot seem to figure out what the issue could be, I don't have any random break statements or anything that should shut down the code. PLEASE HELP

#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;

        }

}
        
        
    

        
    
klutt
  • 30,332
  • 17
  • 55
  • 95
  • "The" scanf statement? You have three. – klutt Oct 29 '21 at 07:47
  • Also, please shorten your code. There's no way all this is needed to demonstrate a problem. Create a [mre]. – klutt Oct 29 '21 at 07:48
  • You are reading line feed characters instead of user input, that's why. This is a super common FAQ. Quick & dirty fix: add a single `getchar();` call after each `scanf`. – Lundin Oct 29 '21 at 08:03
  • Also see [How to read / parse input in C? The FAQ](https://stackoverflow.com/questions/35178520/how-to-read-parse-input-in-c-the-faq), particularly the "Why does my scanf("%d", ...) / scanf("%c", ...) fail?" part. – Lundin Oct 29 '21 at 08:04

0 Answers0