Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:33:01+00:00 2026-06-01T17:33:01+00:00

Everything else works fine but try going to the subtraction or division part (Part

  • 0

Everything else works fine but try going to the subtraction or division part (Part of the exercise is not to ask questions in subtraction that have negative answers or division question that have division by 0 or the answer is less than 1). At first it works, then try answering another question. It gives out this complicated question not included in my initialize function So I tried answering it, and it can still detect a right from wrong answer. Then it gives out this 32 – 9 or 32/9 (Couldn’t answer the division part because it requires a remainder and the question was too complicated). After you give out the correct answer try answering another subtraction/division question and it will crash and give this error out Process returned -1073741819 Whats wrong with my code? Thanks in advance also!
BTW I put comments to the part of my code that is supposed to restrict the division and subtraction

/* Arithmetic Quiz Practice Program */
#include <stdio.h>
#include <stdlib.h>
int numbers[10];
int clear(void);
int initialize(void);
int additionquiz(void);
int subtractionquiz(void);
int multiplicationquiz(void);
int divisionquiz(void);

/* Main Menu */
int main()
{
    while(1==1)
    {
        int choice;
        initialize();
        printf("Arithmetic Quiz 4/10/2012");
        printf("\n1 - Addition Quiz\n2 - Subtraction Quiz\n3 - Multiplication Quiz\n4 - Division Quiz\n5 - Exit Program\n");
        scanf("%d",&choice);
        if(choice==1)
        {
            clear();
            additionquiz();
        }
        else if(choice==2)
        {
            clear();
            subtractionquiz();
        }
        else if(choice==3)
        {
            clear();
            multiplicationquiz();
        }
        else if(choice==4)
        {
            clear();
            divisionquiz();
        }
        else if(choice==5)
        {
            exit(EXIT_SUCCESS);
        }
        else
        {
            printf("\n%cPlease input a valid option\n",7);
            main();
        }
    }
    return 0;
}
/* Function for clearing the page */
int clear()
{
    int i;
    for(i=0;i<25;i++)
    {
        printf("\n");
    }
    return 0;
}
/* Function for initializing the Array */
int initialize()
{
    numbers[0]=9;
    numbers[1]=5;
    numbers[2]=1;
    numbers[3]=4;
    numbers[4]=7;
    numbers[5]=8;
    numbers[6]=3;
    numbers[7]=6;
    numbers[8]=2;
    numbers[9]=0;
    return 0;
}

/* Function for the Addition Quiz */
int additionquiz()
{
    /* Randomizing the question in addition quiz */
    int a,b,diff,ans,again;
    a=0;
    diff=1;
    b=a+diff;
    if(a>9)
    {
        a=0;
        diff++;
    }
    if(diff>9);
    {
        diff=0;
    }

    if(b>9);
    {
        b=0;
    }

    /* Main part of the addition quiz */
    while(1==1)
    {
        printf("\n%d + %d = ",numbers[a],numbers[b]);
        scanf("%d",&ans);
        if(ans==numbers[a]+numbers[b])
        {
            printf("\nYour answer is CORRECT!!!\n");
            a++;
        }
        else
        {
            printf("\nYour answer is WRONG!!!\n");
            additionquiz();
        }   
        /* The loop for addition quiz" */
        while(1==1)
        {
            printf("\n1 - Answer another addition question\n2 - Go back to main menu\n3 - Exit program\n");
            scanf("%d",&again);
            if(again==1)
            {
                clear();
                break;
            }
            else if(again==2)
            {
                clear();
                main();
            }
            else if(again==3)
            {
                exit(EXIT_SUCCESS);
            }
            else
            {
                printf("%cPlease input a valid option.\n",7);
                continue;
            }
        }
        continue;
    }
}
/* Function for the subtraction quiz */
int subtractionquiz()
{
/* Randomizing the question in subtraction quiz */
    int a,b,diff,ans,again;
    a=0;
    diff=1;
    if(a>9)
    {
        a=0;
        diff++;
    }
    if(diff>9);
    {
        diff=0;
    }
    b=a+diff;
    if(b>9);
    {
        b=0;
    }
/* Main part of the subtraction quiz */
    while(1==1)
    {
    /* Not allowing questions with negative answer */
        while(numbers[a]<numbers[b])
            {
                a++;
            }

        printf("\n%d - %d = ",numbers[a],numbers[b]);
        scanf("%d",&ans);
        if(ans==numbers[a]-numbers[b])
        {
            printf("\nYour answer is CORRECT!!!\n");
            a++;
        }
        else
        {
            printf("\nYour answer is WRONG!!!\n");
            subtractionquiz();
        }
        /* Loop for the subtraction quiz */
        while(1==1)
        {
            printf("\n1 - Answer another subtraction question\n2 - Go back to main menu\n3 - Exit program\n");
            scanf("%d",&again);
            if(again==1)
            {
                clear();
                break;
            }
            else if(again==2)
            {
                clear();
                main();
            }
            else if(again==3)
            {
                exit(EXIT_SUCCESS);
            }
            else
            {
                printf("%cPlease input a valid option.\n",7);
                continue;
            }
        }
        continue;
    }
}
/* Function for multiplication quiz */
int multiplicationquiz()
{
    /* Randomizing the multiplication quiz */
    int a,b,diff,ans,again;
    a=0;
    diff=1;
    b=a+diff;
    if(a>9)
    {
        a=0;
        diff++;
    }
    if(diff>9);
    {
        diff=0;
    }

    if(b>9);
    {
        b=0;
    }
    /* Main part of the multiplication quiz */
    while(1==1)
    {
        printf("\n%d x %d = ",numbers[a],numbers[b]);
        scanf("%d",&ans);
        if(ans==numbers[a]*numbers[b])
        {
            printf("\nYour answer is CORRECT!!!\n");
            a++;
        }
        else
        {
            printf("\nYour answer is WRONG!!!\n");
            clear();
            multiplicationquiz();
        }
        /* Loop for multiplication quiz */
        while(1==1)
        {
            printf("\n1 - Answer another multiplication question\n2 - Go back to main menu\n3 - Exit program\n");
            scanf("%d",&again);
            if(again==1)
            {
                clear();
                break;
            }
            else if(again==2)
            {
                clear();
                main();
            }
            else if(again==3)
            {
                exit(EXIT_SUCCESS);
            }
            else
            {
                printf("%cPlease input a valid option.\n",7);
                continue;
            }
        }
        continue;
    }
}
/* Function for division quiz */
int divisionquiz()
{
    /* Randomizing the division quiz */
    int a,b,diff,ans,again,remain;
    a=0;
    diff=1;
    if(a>9)
    {
        a=0;
        diff++;
    }
    if(diff>9);
    {
        diff=0;
    }
    b=a+diff;
    if(b>9);
    {
        b=0;
    }
    /*Main part of the division quiz */
    while(1==1)
    {
        /* Not allowing division by 0 or answers less than 1 */
        if(numbers[b]==0 || (numbers[a]<numbers[b]))
        {
                a++;
                continue;
        }
        printf("%d %% %d =\n",numbers[a],numbers[b]);
        printf("What is the whole number in your answer?\n");
        scanf("%d",&ans);
        printf("\nWhat is the remainder in your answer?(0 if none)\n");
        scanf("%d",&remain);
        if((ans==numbers[a]/numbers[b])&&(remain==numbers[a]%numbers[b]))
        {
                printf("\nYour answer is CORRECT!!!\n");
                a++;
        }
        else
        {
                printf("\nYour answer is WRONG!!!\n");
                divisionquiz();
        }
        /* Loop for division quiz */        
        while(1==1)
        {
            printf("\n1 - Answer another division question\n2 - Go back to main menu\n3 - Exit program\n");
            scanf("%d",&again);
            if(again==1)
            {
                clear();
                break;
            }
            else if(again==2)
            {
                clear();
                main();
            }
            else if(again==3)
            {
                exit(EXIT_SUCCESS);
            }
            else
            {
                printf("%cPlease input a valid option.\n",7);
                continue;
            }
        }
        continue;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:33:02+00:00Added an answer on June 1, 2026 at 5:33 pm

    There are several problems. But the reason you see the strange numbers is that a eventually increments past the end of the numbers[] array into unassigned memory.

    Since you’re starting to learn C, here are some tips.

    initialize(); // Only need to call this once, since the array never changes.
    while(1==1)  // This can be "while(1)"
    {
        int choice;
        printf("Arithmetic Quiz 4/10/2012");
        // You can improve readability by splitting long literals like this.
        printf("\n1 - Addition Quiz\n2 - Subtraction Quiz\n"
          "3 - Multiplication Quiz\n4 - Division Quiz\n5 - Exit Program\n");
        scanf("%d",&choice);
        // You can simplify a list of "else if" statements with "switch",
        // and you might want to call clear() only once:
        /*
        if(choice==1)
        {
            clear();
            additionquiz();
        }
        else if(choice==2)
        . . .
        */
        clear();  // Always call this.
        switch (choice) {
        case 1:
          additionquiz();
          break;
        case 2:
          subtractionquiz();
          break;
        ...
        default:
          printf("\n%cPlease input a valid option\n",7);
          // main(); Not necessary
          break;
      }
    

    When you don’t care about a function’s return value you can declare it to return void. It’s also a good idea to declare a no-args function explicitly:

    /* Function for clearing the page */
    //int clear()
    void clear(void)  // Takes no args, returns nothing.
    {
    

    In each part of the quiz, you need to check a and b inside the while() loop, to ensure they’re always valid when you repeat the same quiz.

    /* Randomizing the multiplication quiz */
    int a,b,diff,ans,again;
    a=0;
    diff=1;
    
    // vvv THIS BLOCK SHOULD BE INSIDE THE while() LOOP vvv
    b=a+diff;
    if(a>9)
    {
        a=0;
        diff++;
    }
    if(diff>9);  // This semicolon causes the next line to be executed always.
    {
        diff=0;
    }
    
    if(b>9);  // This semicolon causes the next line to be executed always.
    {
        b=0;
    }
    // ^^^ THIS BLOCK SHOULD BE INSIDE THE while() LOOP ^^^
    
    /* Main part of the multiplication quiz */
    while(1==1)   // This can be "while(1)"
    {
    

    Finally, since you’re repeating the same validation checks for a and b in each quiz, you might want to extract that code into its own function. Since the function may need to change the values, you’ll need to pass them by address and then dereference the pointers:

    void validate(int *a, int *b, int *diff) {
      if (*a > 9) {  // Validate "a" first, which may alter "diff"
        *a = 0;
        ++*diff;
      }
      if (*diff > 9) {  // Validate "diff"
        *diff = 0;
      }
      *b = *a + diff;  // Calculate and validate "b"
      if (*b > 9);  {
        *b = 0;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not doing a large chunk of computation in JS. Everything works fine
I can't get PHP to recognize the ImageMagick (Imagick) class. Everything else works, the
I can't figure out how to log info-level messages to stdout, but everything else
I'm developing a touchscreen application that, aside from everything else, records the amount of
Everything is fine and the final problem is so annoying. Compile is great but
I have a rails application deployed that works fine in Safari, Firefox, and Opera.
I have a simple login page. Everything works fine in Mozilla and IE. When
How do I make a textarea have the same font as everything else on
I'm developing a real time website using socketstream and backbone.js, everything else was just
Everything was working just fine and on the last publish my wordpress directory is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.