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.
#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;
}
Comments
Leave a comment