Answer to Question #260801 in C++ for Qman

Question #260801

Create a program for multiplication, addition, and subtraction with at least 10 different problems for each mathematical option and report the output/input from the user. When the user enters and answer, display total questions X, Total correct answers Y, Total wrong answers Z.


1
Expert's answer
2021-11-03T17:47:25-0400
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
    int total_questions = 0, correct = 0, wrong = 0;
    int answer;
    char op;
    srand(time(NULL));


    cout<<"Pick an operation: \n";
    cout<<"1. Multiplication\n2. Addition\n3. Subtraction\n";
    cin>>answer;
    switch(answer){
        case 1: op = '*'; break;
        case 2: op = '+'; break;
        case 3: op = '-'; break;
        default: cout<<"Invaid choice\n"; return 0;
    }


    for(int i = 0; i < 10; i++){
        int a = rand() % 100, b = rand() % 100, correct_answer;
        cout<<a<<" "<<op<<" "<<b<<" = ";
        cin>>answer;
        switch(op){
            case '*': correct_answer = a * b; break;
            case '+': correct_answer = a + b; break;
            case '-': correct_answer = a - b; break;
            default: break;
        }
        if(answer == correct_answer) correct++;
        else wrong++;
        total_questions++;
        cout<<"\nTotal questions: "<<total_questions<<endl;
        cout<<"Total correct answers: "<<correct<<endl;
        cout<<"Total wrong answers: "<<wrong<<endl;
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS