include

include

include

include

include

include

typedef struct { int Opp; double numOne; double numTwo; double answer; } questions;

questions createQuestion () {

int lower = 0, upper = 100, count = 1;
srand(time(0));

questions realQuestion;
/*
printf ("What opperation would you like to preform?\n");
scanf ("%c", &realQuestion.Opp);
printf("Input number one: \n");
scanf("%lf", &realQuestion.numOne);
printf("Input number two: \n");
scanf("%lf", &realQuestion.numTwo);
*///printf("Question 1 in realQuestion is %lf and Question 2 is %lf",realQuestion.numOne,realQuestion.numTwo);

for (int i = 0; i < count; i++)
{
    realQuestion.numOne = (rand() % (upper - lower + 1)) + lower;
    realQuestion.numTwo = (rand() % (upper - lower + 1)) + lower;
    realQuestion.Opp = ((rand() % (upper - lower + 1)) + lower) % 4;

}

if(realQuestion.Opp == 0){
    realQuestion.answer = realQuestion.numOne + realQuestion.numTwo;
    realQuestion.Opp = '+';
}
else if(realQuestion.Opp == 1)
{
    realQuestion.answer = realQuestion.numOne - realQuestion.numTwo;
    realQuestion.Opp = '-';
}
else if(realQuestion.Opp == 2)
{
    realQuestion.answer = realQuestion.numOne * realQuestion.numTwo;
    realQuestion.Opp = '*';
}
else
{
    realQuestion.answer = round(realQuestion.numOne / realQuestion.numTwo);
    realQuestion.Opp = '/';
}

return realQuestion;

}

int main () { printf("Welcome to the beginner level test! Round all division questions to the whole number. Good luck! \n\n");

bool answered = false;
double userAnswer;
int count = 0;
double percentage;
char grade;
char procedure[50];
bool passed = false;
bool retakeTrue = false;
char retake;
char retake_str[50];
while (!passed) {
    //createQuestion ();
    for (int i = 0; i < 10; i++)
    {
        questions Q1 = createQuestion();
        //printf("%lf,%lf,%c\n",Q1.numOne,Q1.numTwo,Q1.Opp);
        printf("Solve the following problem: What is %.1lf %c %.1lf?\n", Q1.numOne, Q1.Opp, Q1.numTwo);
        scanf("%lf", &userAnswer);
        if (userAnswer == Q1.answer) {
            count++;
            printf("You got it right!\n");
        } else {
            printf("Incorrect\n");
        }
    }


    percentage = (count / 10.0) * 100;

    if (percentage >= 90) {
        grade = 'A';
    } else if (percentage >= 80) {
        grade = 'B';
    } else if (percentage >= 70) {
        grade = 'C';
    } else if (percentage >= 60) {
        grade = 'D';
    } else {
        grade = 'F';
    }


    printf("You got %d correct, so your grade is %c\n", count, grade);


    if (grade == 'B' || grade == 'A' || grade == 'C')
    {
        passed = true;
        printf("Congrats! You passed the first test so you are elligible to take the higher level test. would you like to proceed? (Y/N)");
        scanf("%s", &procedure[0]);
        do
        {

            if (procedure[0] == 'Y' || procedure[0] == 'y') {
                answered = true;
                passed = true;
                /*HIGHER LEVEL MATH TEST INCOMPLETE
                srand(time(NULL));

                int randomNumber = (rand() % 4) + 1;

                int answerOfUser,realAnswer;
                double answerOfUser2, realAnswer2;

                switch(randomNumber) {

                    case 1 :

                        int a = (rand() % 10) - 5;
                        int b = (rand() % 10) - 5;
                        int c = (rand() % 10) - 5;

                        if(a != 0 && b != 0 && c != 0) {

                            int delta;

                            delta = b*b - (4*a*c);

                            printf("How many solutions are there for the following equation?\n");
                            printf("%dx^2 + %dx + %d = 0\n", a, b, c);
                            printf("There are: ");
                            scanf("%d", &answerOfUser);


                            if(delta > 0) {

                                realAnswer = 2;

                            } else if (delta = 0) {

                                realAnswer = 1;

                            } else {

                                realAnswer = 0;
                            }

                            if(realAnswer == answerOfUser) {

                                printf("Good job! You are correct. There are %d solutions to the equation.", realAnswer);

                            } else {

                                printf("Wrong...There are %d solutions to the equation.", realAnswer);

                            }
                        } else {

                            printf("Error, please try again.");

                        }

                        break;


                    case 2 :

                        a = (rand() % 10) - 5;
                        b = (rand() % 10) - 5;
                        c = (rand() % 10) - 5;

                        if(a != 0) {

                            printf("What is the solution to the equation below\n");
                            printf("%dx + %d = %d\n", a, b, c);
                            printf("The solution is: ");
                            scanf("%d", &answerOfUser);

                            realAnswer = (c - b) / a;

                            if(realAnswer == answerOfUser) {

                                printf("You are correct! The correct answer is %d", realAnswer);

                            } else {

                                printf("Wrong... The correct answer is %d", realAnswer);

                            }

                        } else {

                            printf("Error, please try again");

                        }

                        break;

                    case 3 :

                        a = (rand() % 100);
                        b = (rand() % 100);

                        printf("What is %d percent of %d? You can use a calculator.\n", a, b);
                        printf("The answer is: ");
                        scanf("%lf", &answerOfUser2);

                        realAnswer2 = (b*(a/100.0));

                        if(realAnswer2 == answerOfUser2) {

                            printf("You are right! The correct answer is %0.0lf", realAnswer2);

                        } else {

                            printf("Wrong... The right answer is %0.2lf", realAnswer2);

                        }

                        break;


                    case 4 :

                        a = (rand() % 5);
                        b = (rand() % 10) - 5;
                        c = (rand() % 10) - 5;
                        int d = (rand() % 10) - 5;
                        int e = 0;
                        int f = sqrt(a) + d;
                        int g = b/(2*a);

                        int delta = b*b - (4*a*c);


                        printf("What is the limit of the following function when x approaches infinity?\n");
                        printf("lim sqrt(%dx^2 + %dx + %d) + %dx\n", a, b, c, d);
                        printf("Is it\t1)Infinity\t2)Negative Infinity\t3)A rational number which is %d\n", g);
                        printf("The answer is: ");
                        scanf("%d", &e);

                        if(d < 0 && f == 0) {

                            realAnswer = 3;

                        } else if (d >= 0 || (d < 0 && f > 0)) {

                            realAnswer = 1;

                        } else {

                            realAnswer = 2;

                        }

                        if(realAnswer == e) {

                            printf("You are correct! The correct answer is %d", realAnswer);

                        } else {

                            printf("Wrong... The answer is %d", realAnswer);

                        }

                        break;

                    default:

                        break;
                */

                } else if (procedure[0] == 'N' || procedure[0] == 'n') {
                printf("Thank you for taking the math quiz and great job! :)");
                answered = true;
                passed = true;

            } else {
                printf("Error: please enter a valid response");
                scanf("%s",&procedure[0]);
            }
        }
        while (!answered);
    } else {
        printf("Unfortunately you received a grade of D or lower, so you cannot take the higher level test.\nYou can retake the test to try to for a better score!\nRetake the test? (Y/N)\n");
        scanf("%s",&retake_str[0]);

        while (!retakeTrue) {
            if (retake_str[0] == 'Y' || retake_str[0] == 'y') {
                retakeTrue = true;
                break;

            } else if (retake_str[0] == 'N' || retake_str[0] == 'n') {
                printf("Thank you for taking the math quiz and great job! :)");
                passed = true;
                retakeTrue = true;
                break;

            } else {
                printf("Error: please enter a valid response");
                passed = true;
                scanf("%s",&retake_str[0]);
            }
        }
    }
}
return 0;

}

Built With

Share this project:

Updates

posted an update

include

include

include

include

include

include

include

typedef struct { int Opp; double numOne; double numTwo; double answer; char realOpp[50]; } questions;

questions createQuestion () { int lower = 0, upper = 100, count = 1; srand(time(0));

questions realQuestion;
/*
printf ("What opperation would you like to preform?\n");
scanf ("%c", &realQuestion.Opp);
printf("Input number one: \n");
scanf("%lf", &realQuestion.numOne);
printf("Input number two: \n");
scanf("%lf", &realQuestion.numTwo);
*///printf("Question 1 in realQuestion is %lf and Question 2 is %lf",realQuestion.numOne,realQuestion.numTwo);

for (int i = 0; i < count; i++)
{
    realQuestion.numOne = (rand() % (upper - lower + 1)) + lower;
    realQuestion.numTwo = (rand() % (upper - lower + 1)) + lower;
    realQuestion.Opp = ((rand() % (upper - lower + 1)) + lower) % 4;

}

if(realQuestion.realOpp == 0)
{
    realQuestion.answer = realQuestion.numOne + realQuestion.numTwo;
    strcat(realQuestion.realOpp, "plus");
}
else if(realQuestion.Opp == 1)
{
    realQuestion.answer = realQuestion.numOne - realQuestion.numTwo;
    strcat(realQuestion.realOpp, "minus");
}
else if(realQuestion.Opp == 2)
{
    realQuestion.answer = realQuestion.numOne * realQuestion.numTwo;
    strcat(realQuestion.realOpp, "times");
}
else
{
    realQuestion.answer = round(realQuestion.numOne / realQuestion.numTwo);
    strcat(realQuestion.realOpp, "divided by");
}

return realQuestion;

}

int main() { double userAnswer; int count = 0; double percentage; char grade; bool first = true; for(int i = 0; i < 10; i++) { questions Q1 = createQuestion(); char num1[50]; char num2[50]; char Opp[50]; char equation[50]; char intro[200]; char qNum[50];

    // TTS introduction on first iteration
    if (first) 
    {
        strcpy(intro, "This is a text-to-speech based tool meant to help users practice their arithmetic using only hearing,");
        first = false;
    }

    strcpy(intro, "Question ");
    strcpy(qNum, itoa(i + 1, qNum,10));
    strcat(intro, qNum);

    // TTS question number
    char introCommand[500];
    strcpy(introCommand, "espeak -v m1 -s 140 \"");
    strcat(introCommand, intro);
    strcat(introCommand, "\"");
    system(introCommand);

    // Converting the numbers to strings
    strcpy(num1, itoa(Q1.numOne,num1,10));
    strcpy(num2, itoa(Q1.numTwo, num2, 10));
    // strcpy(Opp, &Q1.realOpp);
    strcat(num1, Q1.realOpp);
    strcat(num1, num2);

    // TTS asks question
    strcpy(equation, num1);
    strcat(equation, "is equal to what?");
    char charCommand[100];
    strcpy(charCommand, "espeak -v m1 -s 140 \"");
    strcat(charCommand, equation);
    strcat(charCommand, "\"");
    system(charCommand);

    printf("What is %.1lf %c %.1lf?\n", Q1.numOne, Q1.realOpp, Q1.numTwo);
    scanf("%lf", &userAnswer);

    if (userAnswer == Q1.answer)
    {
        count++;
        printf("You got it right!\n");
    }
    else
    {
        printf("Incorrect\n");
    }
}

percentage = (count/10.0)*100;

if (percentage>=90)
{
    grade = 'A';
}   
else if (percentage>=80)
{
    grade = 'B';
}
else if (percentage>=70)
{
    grade = 'C';
}
else if (percentage>=60)
{
    grade = 'D';
}
else
{
    grade = 'F';
}

printf("You got %d correct, so your grade is %c",count,grade);

return 0;

}

Our code for incorporating TTS into the quiz. We ran out of time and we had a lot of complications with team member's availability and such, so we weren't able to finish the project fully. There are some bugs in both codes that have yet to be worked out but this is what we have thus far. Our team is me, Enlun Yin, Othmane Harraq, Ryan Chan, and Gaurab (We are all freshman and just wanted to get some experience making a project together, having fun, and being in an environment with higher level programmers and absorb as much information as possible. Thank you OwlHacks for a great time!!!!! :)

Log in or sign up for Devpost to join the conversation.