macOS xterm-256color zsh 623 views

Program in C that let’s you do some math and then quit out when you get tired. I have pasted the C code below. Let’s call it DoMath.C

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

int main() {

srand( (unsigned)time(NULL));
int choice, answer;
int x, y;
int n;


do{
    x = rand() % 101;
    y = rand() % 101; 
    printf("Choose a problem:\n");
    printf("1. Give me an addition problem.\n");
    printf("2. Give me a subtraction problem.\n");
    printf("3. Give me a multiplication problem.\n");
    printf("4. Quit.\n");
    printf(" Enter your choice: ");
    scanf("%i", &choice);



    if(choice==1){
        n = 0;
        while(n < 5 ){

            printf("Complete: %i + %i = ", x, y);
            printf( "Enter a value :");
            scanf("%i", &answer);
                if(answer==x+y){
                    printf("Congrats\n");
                    break;
                }
                else{
                 printf("incorrect, try again\n");
                }
        n++;

        }
    }

//--------------------------------------------------------------------------

    if(choice==2){

        n = 0;
        while(n<5 ){
            printf("Complete: %i - %i = ", x, y);
            printf( "Enter a value :");
            scanf("%i", &answer);
                if(answer==x-y){
                    printf("Congrats\n");
                    break;
                }
                else
                    printf("incorrect, try again\n");
        n++;
        }
    }


//----------------------------------------------------------------------
    if(choice==3){
        n = 0;
        while(n<5){
            x = rand() % 101;
            y = rand() % 101; 
            printf("Complete: %i * %i =", x, y);
            printf( "Enter a value :");
            scanf("%i", &answer);
                if(answer==x*y){
                    printf("Congrats\n");
                    break;
                }
                else
                    printf("incorrect, try again\n");

        n++;
      }

    }

//----------------------------------------------------------------------
   if(choice == 4){
        break;

   }
    else if(choice < 1 || choice > 4)
        printf("Choose different number.\n");


    } while(n >- 1) ;
        printf("goodbye");
}