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

  • Home
  • SEARCH
  • 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 8246657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:34:42+00:00 2026-06-07T22:34:42+00:00

So I am trying to make a program which will generate random basic mathematical

  • 0

So I am trying to make a program which will generate random basic mathematical questions like addition, subtraction, etc.

While I am trying to generate division questions I made a do-while loop which runs until the prerequisite is met for division quesions.

But for some reason when I ask it to generate 20 division questions with none with remainder it always crashes.

Please help

Here’s the code

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int correct,total,MAXVAL;
const char oper[4]={'/','/','/','/'};

typedef struct data{
    int first,second;
    char operation;
}data;

data datagenerator(){
    data newData;
    newData.first= (rand()%MAXVAL);
    newData.operation=oper[rand()%4];
    newData.second=(rand()%MAXVAL);
    return newData;
}

bool corrector(data newData){
    bool isture=false;
    switch(newData.operation){
        case '/':
            if((newData.first%newData.second)==0){
                isture=true;
            }
            break;
        case '*':
            isture=true;
            break;
        case '+':
            isture=true;
            break;
        case '-':
            isture=true;
            break;
    }
    return isture;
}

void quizer(){

    system("CLS");
    for(int counter=1;counter<=total;counter++){
        cout<<"Q"<<counter<<": ";
         data newData;
        do{
            newData=datagenerator();
        }while(!corrector(newData));
        cout<<newData.first<<newData.operation<<newData.second<<"\n";
    }
    cout<<"\nYou got "<<correct<<"/"<<total<<"correct\n";
}


int main(){
    //srand((unsigned)time(0));
    char x;
    cout<<"How many questions do you want?"<<endl;
    cin>>total;
    cout<<"Enter the maximum value\n";
    cin>>MAXVAL;
    cout<<"Are you ready?\n";
    cin>>x;
    quizer();

    system("PAUSE");
    return 0;
}
  • 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-07T22:34:44+00:00Added an answer on June 7, 2026 at 10:34 pm

    Your problem lies right on line 17 and 19. You are dividing by 0, assuming you are setting the value on MAXVAL to 0 when it asks you. With modulo division you need to be careful with that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a program which will create a sum of directories the
I am trying to make a program which will need to execute a lengthy
I'm trying to make a program which creates a spaceship and I'm using the
Hello guys look to my code I'm trying to make a program which asks
Context: I'm trying to do is to make a program which would take text
I'm trying to make a program that can be hosted by many peoples, like
i'm trying to make a program that will connect two points that i click
I'm trying to make a C function which will ask the user to enter
Okay, so I'm trying to make a simple content loader which will evolve into
I am trying to make a program which needs scans in more than one

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.