This is a C++ program that invokes a function calc(), intakes two integers and an arithmetic operator, and prints the corresponding result.
#include <cstdlib>   /* the program works fine without this header but I'm sure it's cool since the library uses a namespace*/     
#include  
        case
'+' :cout<<"\nThe sum of "<<x<<" plus
"<<y<< " is "<<(x+y);
break;
case '-' :cout<<"\nThe difference of "<<x<<" minus "<<y<< " is "<<(x-y);
break;
case '-' :cout<<"\nThe difference of "<<x<<" minus "<<y<< " is "<<(x-y);
       
break;
case '*' :cout<<"\nThe product of "<<x<<" multiplied by "<<y<< " is "<<(x*y);
case '*' :cout<<"\nThe product of "<<x<<" multiplied by "<<y<< " is "<<(x*y);
        break;
        case '/' :cout<<"\nThe
quotient of "<<x<<" divided by "<<y<<
" is "<<(x/y);
        break;
case '%' :cout<<"\nThe reminder of
"<<x<<" divided by "<<y<< " is
"<<(x%y);
        break;
    }
    return 0; /* returns 0 at end of program to show normalcy since the main function 'int main()' demands a value of an integer type be returned */
}

 
No comments:
Post a Comment