Bobby Martins
Bobby Martins

Reputation: 71

second "if" condition faulty for some reason

So this is a tables calculator and I'm using a function which takes user input and based on the user input will either print out a multiplication or division table. However the division choice causes this error to be displayed: "cygwin_exception::open_stackdumpfile: Dumping stack trace to Playground.exe.stackdump"

int main()
{
    int user;
    char decision;

    printf("This is a calculator that can show  multiplication/division table of any number\n");
    printf("Enter your desired number: ");
    scanf("%d",&user);

    clear_stdin();

    printf("Now enter your desired table(d/m): ");
    scanf("%c", &decision);

    getMultiples(user, decision);
    return 0;
    }

void getMultiples(int number, char choice)
{
    if (choice == 'm'){
        for(int i = 0; i<=12; i++){
            printf("\n");
            printf("%d x %d = %d \n", number, i, number*i);
        }
    }

    else if(choice == 'd') {
        for(int i = 0; i<=12; i++){
            printf("\n");
            printf("%d ÷ %d = %d \n", number, i, number/i);
            }
    }

    else {
        printf("Invalid choice, program terminating now.");
    }
    }

Upvotes: 0

Views: 55

Answers (2)

sattva_venu
sattva_venu

Reputation: 715

You are trying to divide by zero for the first iteration. Start your loop with 1 instead of 0 for both multiplication and division

Upvotes: 1

jaxdre
jaxdre

Reputation: 36

You may need to handle the zero case separately. The num/0 might be causing your error. Try starting the division at 1

Upvotes: 2

Related Questions