Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #pragma warning(disable:4996)
- #ifndef __CHARCODES__
- #define __CHARCODES__
- #define INT_UPPER_BOUND 1001
- #define INT_LOWER_BOUND -1001
- #define VOODOO -1024
- #define ZERO 0
- #define MOD 5
- #endif
- int main() {
- // initialize your variables...
- int int1;
- int int2;
- double sol;
- char opr;
- char sym;
- int typeCode = -1;
- //int1 prompt
- printf("Please enter a number between -1000 and 1000:\n");
- scanf("%d", &int1);
- rewind(stdin);
- //input parameters
- while (int1 <= INT_LOWER_BOUND || int1 >= INT_UPPER_BOUND) {
- printf("Yikes, why don't you try that again?\n\nPlease enter a number between -1000 and 1000:\n");
- scanf("%d", &int1);
- rewind(stdin);
- }
- //int2 prompt
- printf("Please enter another number between -1000 and 1000:\n");
- scanf("%d", &int2);
- rewind(stdin);
- //input parameters
- while (int2 != VOODOO && int2 <= INT_LOWER_BOUND || int2 >= INT_UPPER_BOUND) {
- printf("Yikes, why don't you try that again?\n\nPlease enter a number between -1000 and 1000:\n");
- scanf("%d", &int2);
- rewind(stdin);
- }
- //voodoo
- while (int2 == VOODOO) {
- printf("How did I know you would type 'negative one thousand and twenty four?'\n*tsk* *tsk* *tsk*\nNow why don't you try using a valid input?\n");
- scanf("%d", &int2);
- rewind(stdin);
- }
- //NO zeros!
- while (int2 == ZERO) {
- printf("No zeros allowed! Try that again:\n");
- scanf("%d", &int2);
- rewind(stdin);
- }
- //operator prompt
- printf("Choose an operation: (1 - 5)\n\n 1 : +\n 2 : -\n 3 : *\n 4 : /\n 5 : %%\n\n");
- scanf("%c", &opr);
- rewind(stdin);
- while (opr >= '6' || opr <= '0') {
- printf("Why don't you try using a valid input?\n");
- scanf("%c", &opr);
- rewind(stdin);
- }
- //Operator selection logic
- switch (opr) {
- case '1':
- sym = '+';
- sol = int1 + int2;
- break;
- case '2':
- sym = '-';
- sol = int1 - int2;
- break;
- case '3':
- sym = '*';
- sol = int1 * int2;
- break;
- case '4':
- sym = '/';
- sol = (double) int1 / int2;
- break;
- case '5':
- sym = '%';
- sol = int1 % int2;
- break;
- }
- //output
- printf("Here is your problem and its solution:\n\n %d %c %d = %4f\n\n ...press any key to exit", int1, sym, int2, sol);
- _getch();
- return 0;
- }
- // answer the focus question
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement