[Solved] (C) Integer Calculator capable of Cancel and Quit [closed]


Here is your program edited to suit your needs. Everything new is explained in the comments in the code:

#include <stdio.h>
#include <stdlib.h>  // Don't forget # before include!
int main()  {
    char ch = NULL; //character for storing 'q' or 'c'
    do{
    int x = 0;
    int y = 0;
    int r = 0;
    char o;
    printf("*****INTEGER CALCULATOR*****\n\n\n");
    printf("enter x: ");
    scanf("%d",&x);
    printf("enter y: ");
    scanf("%d",&y);
    printf("%d %d\n",x,y);
    printf("+ - * / %% : ");
    scanf(" %c",&o);   //%c not %s as o is a char
    if (o == '+')
        r = x+y;
    else if (o == '-')
        r = x-y;
    else if(o == '*')
        r = x*y;
    else if(o == "https://stackoverflow.com/")
    {
        if (x==0&&y==0) {
            printf("UNDEFINED\n");
        }
        else if(y==0)   {
            printf("ERROR: DIVISION BY ZERO\n");
        }
        else    {
            r= x/y;
        }
    }
    else if(o == '%')
        r= x%y;
    else    {
        printf("OPERATOR ERROR! Try again:\n");
    }
    printf("Operation: %c\n",o);
    printf("RESULT: %d\n\n\n",r);

    while(1)  //infinite loop
    {
        printf("Enter 'c' for calculating once more and q to exit");
        scanf(" %c",&ch);
        if(ch=='c' || ch=='q') // if input is c or q
            break;             //break out of infinite loop
        else                   // if input is not c or q
            printf("Invalid option.Try again\n");//print this and continue the infinite loop
    }
    //ch is now sure to be either c or q when execution reaches here
    }while(ch!='q'); // loop until ch is not q
    return 0;
}

0

solved (C) Integer Calculator capable of Cancel and Quit [closed]