我可以将函数的结果带到另一个函数吗?

时间:2017-07-23 08:41:04

标签: visual-c++

这是我的数学测验程序的一部分。我尝试为我的作业编写一个数学测验,我想为我的数学测验做最终报告,如(int report())所示。当我运行程序时,它说title()(在modeadd()中调用的参数太少。当我在modeadd()中更改title()时与int title()相同, 我不能回到菜单,直接去报告。我怎么能解决这个问题。

void main()
{   
    int add, minus, times, divide;

    menu(&add, &minus, &times, &divide);
    report(add, minus, times, divide);

    printf("\n");
    system("pause");
}

int menu(add, minus, times, divide)
{
    int choice;

        printf("\t\t\t\t\t WELCOME TO THE MATH QUIZ.\n\a");
        printf("\t\t\t IF YOU ARE READY, ENTER '1' FOR YES. IF NOT, ENTER '2' FOR NO.\n");
        printf("\t\t\t\t PLEASE ENTER YOUR CHOICE : ");
        scanf("%d", &choice);
        rewind(stdin);


        while (choice >= 3 || choice <= 0)
            {
                printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
                printf("PLEASE RE-ENTER AGAIN : ");
                scanf("%d", &choice);
                rewind(stdin);
                printf("\n----------------------------------PAGE BREAK------------------------------------\n");
            }

        switch (choice)
        {
        case 1:
            title(add, minus, times, divide);
            break;

        default:
            printf("\t\t\t THANK YOU. WELCOME YOU TO TRY WHEN YOU ARE READY.");
        }
         return choice;
     }

    int title(int*add, int*minus, int*times, int*divide)
     {
        int choice;

    printf("PLEASE CHOOSE THE TITLE YOU WANT CHALLENGE.\n");
    printf("1. ADDITION\n2. SUBTRACTION\n3. MULTIPLICATION\n4. DIVISION\n");
    printf("PLEASE ENTER YOUR CHOICE : ");
    scanf("%d", &choice);
    rewind(stdin);

    while (choice >= 5 || choice <= 0)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
}

        switch (choice)
        {
        case 1:
            printf("YOU CHOICE IS NUMBER 1, ADDITION\n");
            printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
            (*add)++;
            modeadd();
            break;

        case 2:
            printf("YOU CHOICE IS NUMBER 2, SUBTRACTION\n");
            printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
            (*minus)++;
            modeminus();
            break;

        case 3:
            printf("YOU CHOICE IS NUMBER 3, MULTIPLICATION\n");
            printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
            (*times)++;
            modetimes();
            break;

        default:
            printf("YOU CHOICE IS NUMBER 4, DIVISION\n");
            printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
            (*divide)++;
            modedivide();
            break;
        }

    return choice;
 } 

int modeadd()
{
    int choice;

    printf("PLEASE CHOOSE THE DIFFICULT YOU WANT CHALLENGE FOR ADDITION.\n");
    printf("1. BEGINNER\n2. INTERMEDIATE\n3. ADVANCED\n4. QUIT TO MENU\n");
    printf("PLEASE ENTER YOUR CHOICE : ");
    scanf("%d", &choice);
    rewind(stdin);

    while (choice <= 0 || choice >= 5)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
    }

    if (choice == 1)
    {
        printf("YOUR CHOICE IS NUMBER 1, BEGINNER.\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        ABeg();
    }

    else if (choice == 2)
    {
        printf("YOUR CHOICE IS NUMBER 2, INTERMEDIATE.\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        AInter();
    }

    else if (choice == 3)
    {
        printf("YOUR CHOICE IS NUMBER 3, ADVANCED.\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        AAdv();
    }

    else
    {
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        printf("YOU HAVE CHOOSE TO BACK TO MENU. ");
        title();
    }

    return 0;
}

//Addition beginner question
int ABeg()
{
    int    response, i, corAns, wrongAns, num2, num1;
    double answer, correct;

    printf("PLEASE ENTER THE NUMBER OF QUESTION YOU WANT TO TRY : ");
    scanf("%d", &response);
    rewind(stdin);

    while (response < 0)
    {
        printf("PLEASE ENTER A VALID NUMBER : ");
        scanf("%d", &response);
        rewind(stdin);
    }

    printf("PLEASE ENTER YOUR ANSWER.\n");

    if (response == 0)
    {
        printf("\nTHANKS FOR PLAYING!!!\n");
        return 0;
    }

    else
    {
        corAns = 0;
        wrongAns = 0;
        for (i = 1; i <= response; i++)
        {
            srand(time(NULL));
            num1 = rand() % 21;
            num2 = rand() % 21;
            correct = num1 + num2;

            printf("\n%d. %d + %d = ", i, num1, num2);
            scanf("%lf", &answer);
            rewind(stdin);

            if (answer == correct)
            {
                printf("I KNOW YOU WILL ANSWERED IT CORRECTLY.\n");
                corAns++;
            }

            else
            {
                printf("SORRY BUT GOOD TRY. THE CORRECT ANSWER IS %.0f.\n", correct);
                wrongAns++;
            }
        }

        printf("\nYOUR RESULT\n");
        printf("===========\n");
        printf("CORRECT ANSWER = %d QUESTION\n", corAns);
        printf("INCORRECT ANSWER = %d QUESTION\n", wrongAns);

        if (corAns == response)
        {
            printf("YOU ARE SO HIGHLY INTELLIGENT :). YOU GET THEM ALL RIGHT!!!\n");
            nextadd();
        }
        else if (corAns == wrongAns)
        {
            printf("GOOD TRY BUT YOU ARE NEARLY FAIL. KEEP WORKING HARDER AND YOU WILL DO BETTER NEXT TIME.\n");
            failadd();
        }
        else if (corAns > wrongAns)
        {
            printf("YOUR CORRECT ANSWER IS ABOVE HALF. GREAT JOB! XD. PLAY THE GAME AGAIN SOON.\n");
            nextadd();
        }
        else
        {
            printf("YOU HAVE FAIL IN THIS MATH QUIZ :(. PLEASE DO THE REVISION.\n");
            failadd();
        }
    }
    return 0;
}    

//Asking after addition question
int nextadd()
{
    int choice;

    printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
    printf("DID YOU WANT TO CHALLENGE HARDER QUESTION? OR DIFFERENT ARITHMETIC? OR ELSE.\n");
    printf("1. CHALLENGE SAME OR DIFFERENT LEVEL WITH SAME ARITHMETIC.\n");
    printf("2. DIFFERENT ARITHMETIC.\n");
    printf("3. NO, I WANT TO QUIT THE QUIZ.\n");
    printf("PLEASE ENTER YOUR ANSWER : ");
    scanf("%d", &choice);
    rewind(stdin);

    while (choice >= 4 || choice <= 0)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
}

    switch (choice)
    {
    case 1:
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
        modeadd();
        break;
    case 2:
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
        title();
        break;
    default:
        printf("THANK YOU FOR YOUR PLAYING.");
    }

    return 0;
}

int report(int add, int minus, int times, int divide)
{
    printf("\n============\n");
    printf("FINAL REPORT\n");
    printf("============\n");
    printf("YOU HAVE PLAY ADDITION FOR %d TIMES\n", add);
    printf("YOU HAVE PLAY SUBTRACTION FOR %d TIMES\n", minus);
    printf("YOU HAVE PLAY MULTIPLICATION FOR %d TIMES\n", times);
    printf("YOU HAVE PLAY DIVISION FOR %d TIMES\n", divide);

    return 0;
}

3 个答案:

答案 0 :(得分:0)

我无法在你的代码中找到你的数学函数的任何定义

modeadd();
modeminus();
modetimes();
modedivide();

在代码中定义上述函数并编译程序

例如

void modeadd()
{
int a,b;
printf("Please enter the value for A=");
scanf("%d",&a);
printf("Please enter the value for B=");
scanf("%d",&b);
printf("A+B=%d",a+b);
}

答案 1 :(得分:0)

首先欢迎来到StackOverflow。

当询问有关错误的问题时,如果您说出错误是什么,那么它是有帮助的,而不仅仅是声明存在错误。

但是,在您的情况下,我从您的代码中假设您的“错误”是,无论您玩多少次,您的报告都显示您在每个类别中都玩了0次。

这是因为范围。您在title()和report()中声明变量add,minus,times和divide。因此,这些变量仅对这些例程是局部的,并且当控制从它们传递时有效地丢失。您的报告仅显示0,因为这是这些变量包含的report()中唯一的值。

要解决这个问题,你需要做两件事之一;或者在类中包含你的代码并将变量声明为该类的字段并从title()和report()中删除声明,或者在main()中将它们声明为变量并通过引用传递给menu()(和转到title())和report()。您需要通过引用传递,否则被调用的例程只获取值的副本,这意味着在从被调用例程退出时,对变量的任何更改都将丢失。

修改

只是有一点空闲时间,所以我能够修改你的代码。这就是我所拥有的:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void main()
{
    int add, minus, times, divide;
    add = minus = times = divide = 0;
    int choice = 1;
    while (choice == 1)
    {
        choice = menu(&add, &minus, &times, &divide);
    }
    report(add, minus, times, divide);

    printf("\n");
    system("pause");
}

int menu(int * add, int * minus, int * times, int * divide)
{
    int choice;

    printf("\t\t\t\t\t WELCOME TO THE MATH QUIZ.\n\a");
    printf("\t\t\t IF YOU ARE READY, ENTER '1' FOR YES. IF NOT, ENTER '2' FOR NO.\n");
    printf("\t\t\t\t PLEASE ENTER YOUR CHOICE : ");
    scanf_s("%d", &choice);
    rewind(stdin);


    while (choice >= 3 || choice <= 0)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf_s("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
    }

    switch (choice)
    {
    case 1:
        title(add, minus, times, divide);
        break;

    default:
        printf("\t\t\t THANK YOU. WELCOME YOU TO TRY WHEN YOU ARE READY.");
    }
    return choice;
}

void failadd(int * add, int * minus, int * times, int * divide)
{
    return;
}

int modeadd(int * add, int * minus, int * times, int * divide)
{
    int choice;

    printf("PLEASE CHOOSE THE DIFFICULT YOU WANT CHALLENGE FOR ADDITION.\n");
    printf("1. BEGINNER\n2. INTERMEDIATE\n3. ADVANCED\n4. QUIT TO MENU\n");
    printf("PLEASE ENTER YOUR CHOICE : ");
    scanf_s("%d", &choice);
    rewind(stdin);

    while (choice <= 0 || choice >= 5)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf_s("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
    }

    if (choice == 1)
    {
        printf("YOUR CHOICE IS NUMBER 1, BEGINNER.\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        ABeg(add, minus, times, divide);
    }

    else if (choice == 2)
    {
        printf("YOUR CHOICE IS NUMBER 2, INTERMEDIATE.\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        AInter(add, minus, times, divide);
    }

    else if (choice == 3)
    {
        printf("YOUR CHOICE IS NUMBER 3, ADVANCED.\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        AAdv(add, minus, times, divide);
    }

    else
    {
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        printf("YOU HAVE CHOOSE TO BACK TO MENU. ");
        title(add, minus, times, divide);
    }

    return 0;
}

//Addition beginner question
int ABeg(int * add, int * minus, int * times, int * divide)
{
    int    response, i, corAns, wrongAns, num2, num1;
    double answer, correct;

    printf("PLEASE ENTER THE NUMBER OF QUESTION YOU WANT TO TRY : ");
    scanf_s("%d", &response);
    rewind(stdin);

    while (response < 0)
    {
        printf("PLEASE ENTER A VALID NUMBER : ");
        scanf_s("%d", &response);
        rewind(stdin);
    }

    printf("PLEASE ENTER YOUR ANSWER.\n");

    if (response == 0)
    {
        printf("\nTHANKS FOR PLAYING!!!\n");
        return 0;
    }

    else
    {
        (*add)++;
        corAns = 0;
        wrongAns = 0;
        for (i = 1; i <= response; i++)
        {
            srand(time(NULL));
            num1 = rand() % 21;
            num2 = rand() % 21;
            correct = num1 + num2;

            printf("\n%d. %d + %d = ", i, num1, num2);
            scanf_s("%lf", &answer);
            rewind(stdin);

            if (answer == correct)
            {
                printf("I KNOW YOU WILL ANSWERED IT CORRECTLY.\n");
                corAns++;
            }

            else
            {
                printf("SORRY BUT GOOD TRY. THE CORRECT ANSWER IS %.0f.\n", correct);
                wrongAns++;
            }
        }

        printf("\nYOUR RESULT\n");
        printf("===========\n");
        printf("CORRECT ANSWER = %d QUESTION\n", corAns);
        printf("INCORRECT ANSWER = %d QUESTION\n", wrongAns);

        if (corAns == response)
        {
            printf("YOU ARE SO HIGHLY INTELLIGENT :). YOU GET THEM ALL RIGHT!!!\n");
            nextadd(add, minus, times, divide);
        }
        else if (corAns == wrongAns)
        {
            printf("GOOD TRY BUT YOU ARE NEARLY FAIL. KEEP WORKING HARDER AND YOU WILL DO BETTER NEXT TIME.\n");
            failadd(add, minus, times, divide);
        }
        else if (corAns > wrongAns)
        {
            printf("YOUR CORRECT ANSWER IS ABOVE HALF. GREAT JOB! XD. PLAY THE GAME AGAIN SOON.\n");
            nextadd(add, minus, times, divide);
        }
        else
        {
            printf("YOU HAVE FAIL IN THIS MATH QUIZ :(. PLEASE DO THE REVISION.\n");
            failadd(add, minus, times, divide);
        }
    }
    return 0;
}

int AInter(int * add, int * minus, int * times, int * divide)
{
    return 0;
}

int AAdv(int * add, int * minus, int * times, int * divide)
{
    return 0;
}
//Asking after addition question

int nextadd(int * add, int * minus, int * times, int * divide)
{
    int choice;

    printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
    printf("DID YOU WANT TO CHALLENGE HARDER QUESTION? OR DIFFERENT ARITHMETIC? OR ELSE.\n");
    printf("1. CHALLENGE SAME OR DIFFERENT LEVEL WITH SAME ARITHMETIC.\n");
    printf("2. DIFFERENT ARITHMETIC.\n");
    printf("3. NO, I WANT TO QUIT THE QUIZ.\n");
    printf("PLEASE ENTER YOUR ANSWER : ");
    scanf_s("%d", &choice);
    rewind(stdin);

    while (choice >= 4 || choice <= 0)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf_s("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
    }

    switch (choice)
    {
    case 1:
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
        modeadd(add, minus, times, divide);
        break;
    case 2:
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
        title(add, minus, times, divide);
        break;
    default:
        printf("THANK YOU FOR YOUR PLAYING.");
    }

    return 0;
}

void modeminus(int * add, int * minus, int * times, int * divide)
{
    return;
}

void modetimes(int * add, int * minus, int * times, int * divide)
{
    return;
}

void modedivide(int * add, int * minus, int * times, int * divide)
{
    return;
}

int title(int * add, int * minus, int * times, int * divide)
{
    int choice;

    printf("PLEASE CHOOSE THE TITLE YOU WANT CHALLENGE.\n");
    printf("1. ADDITION\n2. SUBTRACTION\n3. MULTIPLICATION\n4. DIVISION\n");
    printf("PLEASE ENTER YOUR CHOICE : ");
    scanf_s("%d", &choice);
    rewind(stdin);

    while (choice >= 5 || choice <= 0)
    {
        printf("INVALID NUMBER, PLEASE TRY AGAIN.\n");
        printf("PLEASE RE-ENTER AGAIN : ");
        scanf_s("%d", &choice);
        rewind(stdin);
        printf("\n----------------------------------PAGE BREAK------------------------------------\n");
    }

    switch (choice)
    {
    case 1:
        printf("YOU CHOICE IS NUMBER 1, ADDITION\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        modeadd(add, minus, times, divide);
        break;

    case 2:
        printf("YOU CHOICE IS NUMBER 2, SUBTRACTION\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        modeminus(add, minus, times, divide);
        break;

    case 3:
        printf("YOU CHOICE IS NUMBER 3, MULTIPLICATION\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        modetimes(add, minus, times, divide);
        break;

    default:
        printf("YOU CHOICE IS NUMBER 4, DIVISION\n");
        printf("\n----------------------------------PAGE BREAK------------------------------------\n\n");
        modedivide(add, minus, times, divide);
        break;
    }

    return choice;
}

int report(int add, int minus, int times, int divide)
{
    printf("\n============\n");
    printf("FINAL REPORT\n");
    printf("============\n");
    printf("YOU HAVE PLAY ADDITION FOR %d TIMES.\n", add);
    printf("YOU HAVE PLAY SUBTRACTION FOR %d TIMES.\n", minus);
    printf("YOU HAVE PLAY MULTIPLICATION FOR %d TIMES.\n", times);
    printf("YOU HAVE PLAY DIVISION FOR %d TIMES.\n", divide);

    return 0;
}

有几点需要注意。在c中没有“传递引用”之类的东西,而是传递变量的地址(这个地址本身是通过值传递的),通过在变量名前加上&amp ;.取消引用地址(带*)表示您可以操作位于该地址的值。

我在while循环中包含了对menu()的调用,否则程序将在第一次计算后结束,这不是你的意图。

在menu()中,注意它将变量传递给title()而没有&amp ;.这是因为它收到的变量已经是指向地址的指针,所以你可以按原样传递它们。

title()通过取消引用它们来递增计数器,例如(*添加)++;如果您没有取消引用它们,那么您正在递增地址,这将无法获得您想要的效果!

我为modeadd()等包含了空例程。这些需要完成。

HTH

REVISION

我做了另一个改变,以展示别的东西。我已将参数更改为report()到int而不是int的地址。这是因为report()只需要知道值,它不会增加它们。现在注意main()中的menu()和report()调用的区别。

最新变化

添加,减去,次数和除法现在到处传递。此外,我已将添加计数器的增量移至ABeg()。这在这里更有意义,因为如果用户实际选择回答一些问题,你可以确保它只会增加!

答案 2 :(得分:0)

作为替代方案,我在这里举例说明如何使用c ++和类完全相同。除了标准输入/输出的不同语法之外,关键区别在于add,minus,times和divide都是类的私有成员。这意味着所有例程都可以自动访问它们。这反过来意味着您不必在整个时间内传递它们,而且您也不需要关心传递地址或值。

#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>

using namespace std;

class MathQuiz
{
public:
    MathQuiz()
    {
        add = minus = times = divide = 0;
    }
    int menu()
    {
        int choice;

        cout << "\t\t\t\t\t WELCOME TO THE MATH QUIZ.\n\a";
        cout << "\t\t\t IF YOU ARE READY, ENTER '1' FOR YES. IF NOT, ENTER '2' FOR NO.\n";
        cout << "\t\t\t\t PLEASE ENTER YOUR CHOICE : ";
        cin >> choice;
        system("cls");

        while (choice >= 3 || choice <= 0)
        {
            cout << "INVALID NUMBER, PLEASE TRY AGAIN.\n";
            cout << "PLEASE RE-ENTER AGAIN : ";
            cin >> choice;
            system("cls");
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n";
        }

        switch (choice)
        {
        case 1:
            title();
            break;

        default:
            cout << "\t\t\t THANK YOU. WELCOME YOU TO TRY WHEN YOU ARE READY.";
        }
        return choice;
    }

    int report()
    {
        cout << "\n============\n";
        cout << "FINAL REPORT\n";
        cout << "============\n";
        cout << "YOU HAVE PLAY ADDITION FOR " + to_string(add) + " TIMES.\n";
        cout << "YOU HAVE PLAY SUBTRACTION FOR " + to_string(minus) + " TIMES.\n";
        cout << "YOU HAVE PLAY MULTIPLICATION FOR " + to_string(times) + " TIMES.\n";
        cout << "YOU HAVE PLAY DIVISION FOR " + to_string(divide) + " TIMES.\n";

        return 0;
    }


private:
    int add, minus, times, divide;

    void failadd()
    {
        return;
    }

    int modeadd()
    {
        int choice;

        cout << "PLEASE CHOOSE THE DIFFICULT YOU WANT CHALLENGE FOR ADDITION.\n";
        cout << "1. BEGINNER\n2. INTERMEDIATE\n3. ADVANCED\n4. QUIT TO MENU\n";
        cout << "PLEASE ENTER YOUR CHOICE : ";
        cin >> choice;
        system("cls");

        while (choice <= 0 || choice >= 5)
        {
            cout << "INVALID NUMBER, PLEASE TRY AGAIN.\n";
            cout << "PLEASE RE-ENTER AGAIN : ";
            cin >> choice;
            system("cls");
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n";
        }

        if (choice == 1)
        {
            cout << "YOUR CHOICE IS NUMBER 1, BEGINNER.\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            ABeg();
        }

        else if (choice == 2)
        {
            cout << "YOUR CHOICE IS NUMBER 2, INTERMEDIATE.\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            AInter();
        }

        else if (choice == 3)
        {
            cout << "YOUR CHOICE IS NUMBER 3, ADVANCED.\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            AAdv();
        }

        else
        {
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            cout << "YOU HAVE CHOOSE TO BACK TO MENU. ";
            title();
        }

        return 0;
    }

    //Addition beginner question
    int ABeg()
    {
        int    response, i, corAns, wrongAns, num2, num1;
        double answer, correct;

        cout << "PLEASE ENTER THE NUMBER OF QUESTION YOU WANT TO TRY : ";
        cin >> response;
        system("cls");

        while (response < 0)
        {
            cout << "PLEASE ENTER A VALID NUMBER : ";
            cin >> response;
            system("cls");
        }

        cout << "PLEASE ENTER YOUR ANSWER.\n";

        if (response == 0)
        {
            cout << "\nTHANKS FOR PLAYING!!!\n";
            return 0;
        }

        else
        {
            add++;
            corAns = 0;
            wrongAns = 0;
            for (i = 1; i <= response; i++)
            {
                srand(time(0));
                num1 = rand() % 21;
                num2 = rand() % 21;
                correct = num1 + num2;

                cout << to_string(i) + ". " + to_string(num1) + " \+ " + to_string(num2) + " = ";
                cin >> answer;
                system("cls");

                if (answer == correct)
                {
                    cout << "I KNOW YOU WILL ANSWERED IT CORRECTLY.\n";
                    corAns++;
                }

                else
                {
                    cout << "SORRY BUT GOOD TRY. THE CORRECT ANSWER IS " + to_string(correct) + "\n";
                    wrongAns++;
                }
            }

            cout << "\nYOUR RESULT\n";
            cout << "===========\n";
            cout << "CORRECT ANSWER = " + to_string(corAns) + " QUESTION\n";
            cout << "INCORRECT ANSWER = " + to_string(wrongAns) + " QUESTION\n";

            if (corAns == response)
            {
                cout << "YOU ARE SO HIGHLY INTELLIGENT :). YOU GET THEM ALL RIGHT!!!\n";
                nextadd();
            }
            else if (corAns == wrongAns)
            {
                cout << "GOOD TRY BUT YOU ARE NEARLY FAIL. KEEP WORKING HARDER AND YOU WILL DO BETTER NEXT TIME.\n";
                failadd();
            }
            else if (corAns > wrongAns)
            {
                cout << "YOUR CORRECT ANSWER IS ABOVE HALF. GREAT JOB! XD. PLAY THE GAME AGAIN SOON.\n";
                nextadd();
            }
            else
            {
                cout << "YOU HAVE FAIL IN THIS MATH QUIZ :(. PLEASE DO THE REVISION.\n";
                failadd();
            }
        }
        return 0;
    }

    int AInter()
    {
        return 0;
    }

    int AAdv()
    {
        return 0;
    }
    //Asking after addition question

    int nextadd()
    {
        int choice;

        cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
        cout << "DID YOU WANT TO CHALLENGE HARDER QUESTION? OR DIFFERENT ARITHMETIC? OR ELSE.\n";
        cout << "1. CHALLENGE SAME OR DIFFERENT LEVEL WITH SAME ARITHMETIC.\n";
        cout << "2. DIFFERENT ARITHMETIC.\n";
        cout << "3. NO, I WANT TO QUIT THE QUIZ.\n";
        cout << "PLEASE ENTER YOUR ANSWER : ";
        cin >> choice;
        system("cls");

        while (choice >= 4 || choice <= 0)
        {
            cout << "INVALID NUMBER, PLEASE TRY AGAIN.\n";
            cout << "PLEASE RE-ENTER AGAIN : ";
            cin >> choice;
            system("cls");
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n";
        }

        switch (choice)
        {
        case 1:
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n";
            modeadd();
            break;
        case 2:
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n";
            title();
            break;
        default:
            cout << "THANK YOU FOR YOUR PLAYING.";
        }

        return 0;
    }

    void modeminus()
    {
        return;
    }

    void modetimes()
    {
        return;
    }

    void modedivide()
    {
        return;
    }

    int title()
    {
        int choice;

        cout << "PLEASE CHOOSE THE TITLE YOU WANT CHALLENGE.\n";
        cout << "1. ADDITION\n2. SUBTRACTION\n3. MULTIPLICATION\n4. DIVISION\n";
        cout << "PLEASE ENTER YOUR CHOICE : ";
        cin >> choice;
        system("cls");

        while (choice >= 5 || choice <= 0)
        {
            cout << "INVALID NUMBER, PLEASE TRY AGAIN.\n";
            cout << "PLEASE RE-ENTER AGAIN : ";
            cin >> choice;
            system("cls");
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n";
        }

        switch (choice)
        {
        case 1:
            cout << "YOU CHOICE IS NUMBER 1, ADDITION\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            modeadd();
            break;

        case 2:
            cout << "YOU CHOICE IS NUMBER 2, SUBTRACTION\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            modeminus();
            break;

        case 3:
            cout << "YOU CHOICE IS NUMBER 3, MULTIPLICATION\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            modetimes();
            break;

        default:
            cout << "YOU CHOICE IS NUMBER 4, DIVISION\n";
            cout << "\n----------------------------------PAGE BREAK------------------------------------\n\n";
            modedivide();
            break;
        }

        return choice;
    }


};

int main()
{
    MathQuiz quiz;
    int choice = 1;
    while (choice == 1)
    {
        choice = quiz.menu();
    }
    quiz.report();

    cout << "\n";
    cin.ignore();
    cin.get();
}