im just so stressed and having a mind block.. i have code please help

#include <stdio.h>
/*pre-defined processor statements*/
#ifndef __OPERATION__
#define __OPERATION__
#define TOTAL 0
#define ADDITION 1
#define SUBTRACTION  2
#define MULTIPLICATION 3
#define	DIVISION 4
#define MODULAR 5
#endif



int main() {
	/*assign the variables*/
	int num1 = 0;
	int num2 = 0;

	char operation;
	char operation2;
	int total = 0;

	
	/*modular is q while m is multiplication*/
	printf(" Programming Assignment #2 - by Geoffrey \n");
	printf("\n");
	
	/* asking user for one input*/
	printf("please enter the First Number:");
	scanf("%d", &num1);
	fflush(stdin);
	
	/* checks if the first user input is within range( bounds checking)*/
	while (num1 < -1000 || num1 > 1000) {
		printf("out of bounds\n");
		printf("please enter the First Number:");
		scanf("%d", &num1);
		fflush(stdin);

	}

	/* ask user for second input*/
	printf("please enter the Second Number:");
	scanf("%d", &num2);
	fflush(stdin);
	
	/* checks if the second user input is within range (bounds checking)*/
	while (num2 < -1000 || num2 > 1000) {
		printf("out of bounds\n");
		printf("please enter the Second number");
		scanf("%d", &num2);
		fflush(stdin);
	}


			
	/* tells user for the next step as prompted*/
	
		printf("Please select an operation to put in the blank space\n");
		printf("%d__%d= \n", num1, num2);
		printf("\n\n");
		printf("type the associated letter and press enter:\n");
		printf(" A - Addition\n S - Subtraction\n M - Multiplication\n D - Division\n Q - Modular\n");

		/* use scanf to receive the letter for the operation*/
		scanf("%d", operation2);
				
	/* uss a switch case structure to use the user input calculator math */
	switch (operation2)
	{
		case ADDITION : total = num1 + num2;
			operation = '+';
		break;

		case SUBTRACTION: total = num1 - num2;
			operation = '-';
		break;

		case MULTIPLICATION: total = num1 * num2;
			operation = '*';
		break;

		case DIVISION: total = num1 / num2;
			operation = '/';
		break;

		case MODULAR: 
			total = num1 % num2;
			operation = '%';
		break;

		default: printf("Invalid Letter selected\n");

	}





			
	return(0);
}

Edited 7 Years Ago by geoffy0404: n/a

I know my problem is within the SWITCH CASE!!

You might get a faster reply if you told us what's wrong..

Here are your Errors...

Err 1:
Line 67 :

scanf("%d", operation2);

It should be

scanf("%c", &operation2);

Err 2:
Your macros are completely useless in this case.Even though you can change them to correct the mistake I would suggest an alternate way.

scanf("%c", operation2);
				
/* uss a switch case structure to use the user input calculator math */
switch (operation2)
{
                case 'a': 
		case  'A': total = num1 + num2;
			operation = '+';
		break;

                case 's': 
		case 'S': total = num1 - num2;
			operation = '-';
		break;

                case 'm':
		case 'M': total = num1 * num2;
			operation = '*';
		break;

                case 'd':
		case 'D': total = num1 / num2;
			operation = '/';
		break;

               case 'q':
		case 'Q': 
			total = num1 % num2;
			operation = '%';
		break;

		default: printf("Invalid Letter selected\n");
}

Err 3:
What you are doing is mixing the concepts.Don't do it. Try to clarify your doubts and have a clear conceptual of MACROS and where they are used and where do we need to sue variables.And ya also try to have a look on why fflush(stdin) is bad and should be avoided.
You'll always find help in this community as long as you show some hard work from your side.

Edited 7 Years Ago by csurfer: n/a

Look in Preprocessor Statements..you defined wrong values like 0..1..2..

Buy you are taking input as 'A', 'S','M'....So you should define constants with ASCII values of A, S, M, D...

Eg:- #define ADDITION 65........like that

I want to print the operation of num1 and num2 using eithor addition, subtraction, multiplication, division, or modular, in my case, i need to use the case switch .

I know my problem is within the SWITCH CASE!!

Plenty of thing are erroneous in your snippet, however I would like to point out the cause of your affliction for now.

printf(" A - Addition\n S - Subtraction\n M - Multiplication\n D - Division\n Q - Modular\n");

/* use scanf to receive the letter for the operation*/
scanf("%d", &operation2);

If you expect a letter, how come you are asking scanf() to parse an integer?
A why a letter, when you define ADDITION, SUBTRACTION, etc... as integer constants?

Edited 7 Years Ago by Aia: n/a

Here YOU go....Analyse th eProgram

#include <stdio.h>

/*pre-defined processor statements*/

#ifndef __OPERATION__

#define __OPERATION__

#define TOTAL 0

#define ADDITION 65

#define SUBTRACTION  83

#define MULTIPLICATION 77

#define DIVISION 68

#define MODULAR 81

#endif







int main() {

    /*assign the variables*/

    int num1 = 0;

    int num2 = 0;



    char operation;

    char operation2;

    int total = 0;





    /*modular is q while m is multiplication*/

    printf(" Programming Assignment #2 - by Geoffrey \n");

    printf("\n");



    /* asking user for one input*/

    printf("please enter the First Number:");

    scanf("%d", &num1);

    fflush(stdin);



    /* checks if the first user input is within range( bounds checking)*/

    while (num1 < -1000 || num1 > 1000) {

        printf("out of bounds\n");

        printf("please enter the First Number:");

        scanf("%d", &num1);

        fflush(stdin);



    }



    /* ask user for second input*/

    printf("please enter the Second Number:");

    scanf("%d", &num2);

    fflush(stdin);



    /* checks if the second user input is within range (bounds checking)*/

    while (num2 < -1000 || num2 > 1000) {

        printf("out of bounds\n");

        printf("please enter the Second number");

        scanf("%d", &num2);

        fflush(stdin);

    }







    /* tells user for the next step as prompted*/



        printf("Please select an operation to put in the blank space\n");

        printf("%d__%d= \n", num1, num2);

        printf("\n\n");

        printf("type the associated letter and press enter:\n");

        printf(" A - Addition\n S - Subtraction\n M - Multiplication\n D - Division\n Q - Modular\n");



        /* use scanf to receive the letter for the operation*/

        scanf("%d", operation2);



    /* uss a switch case structure to use the user input calculator math */

    switch (operation2)

    {

        case ADDITION : total = num1 + num2;

            operation = '+';

        break;



        case SUBTRACTION: total = num1 - num2;

            operation = '-';

        break;



        case MULTIPLICATION: total = num1 * num2;

            operation = '*';

        break;



        case DIVISION: total = num1 / num2;

            operation = '/';

        break;



        case MODULAR: 

            total = num1 % num2;

            operation = '%';

        break;



        default: printf("Invalid Letter selected\n");



    }













    return(0);

}





#include <stdio.h>

/*pre-defined processor statements*/

#ifndef __OPERATION__

#define __OPERATION__

#define TOTAL 0

#define ADDITION 1

#define SUBTRACTION  2

#define MULTIPLICATION 3

#define DIVISION 4

#define MODULAR 5

#endif







int main() {

    /*assign the variables*/

    int num1 = 0;

    int num2 = 0;



    char operation;

    char operation2;

    int total = 0;





    /*modular is q while m is multiplication*/

    printf(" Programming Assignment #2 - by Geoffrey \n");

    printf("\n");



    /* asking user for one input*/

    printf("please enter the First Number:");

    scanf("%d", &num1);

    fflush(stdin);



    /* checks if the first user input is within range( bounds checking)*/

    while (num1 < -1000 || num1 > 1000) {

        printf("out of bounds\n");

        printf("please enter the First Number:");

        scanf("%d", &num1);

        fflush(stdin);



    }



    /* ask user for second input*/

    printf("please enter the Second Number:");

    scanf("%d", &num2);

    fflush(stdin);



    /* checks if the second user input is within range (bounds checking)*/

    while (num2 < -1000 || num2 > 1000) {

        printf("out of bounds\n");

        printf("please enter the Second number");

        scanf("%d", &num2);

        fflush(stdin);

    }







    /* tells user for the next step as prompted*/



        printf("Please select an operation to put in the blank space\n");

        printf("%d__%d= \n", num1, num2);

        printf("\n\n");

        printf("type the associated letter and press enter:\n");

        printf(" A - Addition\n S - Subtraction\n M - Multiplication\n D - Division\n Q - Modular\n");



        /* use scanf to receive the letter for the operation*/

        scanf("%d", operation2);



    /* uss a switch case structure to use the user input calculator math */

    switch (operation2)

    {

        case ADDITION : total = num1 + num2;

            operation = '+';

        break;



        case SUBTRACTION: total = num1 - num2;

            operation = '-';

        break;



        case MULTIPLICATION: total = num1 * num2;

            operation = '*';

        break;



        case DIVISION: total = num1 / num2;

            operation = '/';

        break;



        case MODULAR: 

            total = num1 % num2;

            operation = '%';

        break;



        default: printf("Invalid Letter selected\n");



    }

 printf("RESULT:: %d %c %d = %d", &num1, &operation, &num2, &total);












    return(0);

}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I didn't really Understand...Why everyone is missing the Importance of #define statements in begining of the program, and using THE same constants in Switch case....Did you get the INTENTION of that program....So in this case...you should scan for an integer value to put into operation2...SO IT SHOULD BE %d

Know the Intention of using #Define Constants in Switch Statements...So you should accept A as its ASCII Value.... it should be %d...Syntax Error in my Program...scanf("%d", operation2); should be scanf("%d", &operation2);

Plenty of thing are erroneous in your snippet, however I would like to point out the cause of your affliction for now.

printf(" A - Addition\n S - Subtraction\n M - Multiplication\n D - Division\n Q - Modular\n");

/* use scanf to receive the letter for the operation*/
scanf("%d", &operation2);

If you expect a letter, how come you are asking scanf() to parse an integer?
A why a letter, when you define ADDITION, SUBTRACTION, etc... as integer constants?

i think someone else pointed that out, i think im gonna use this..

scanf("%c", &operation2);
fflush(stdin);


also fflush(stdin) is the only way my teacher taught us how to make user inputs and the enter stroke key work together.

OKAY IT WORKS! heres the code that works THANKS TO ALL!

#include <stdio.h>
/*pre-defined processor statements*/
#ifndef __OPERATION__
#define __OPERATION__
#define TOTAL 0
#define ADDITION 65
#define SUBTRACTION  83
#define MULTIPLICATION 77
#define	DIVISION 68
#define MODULAR 81
#endif



int main() {
	/*assign the variables*/
	int num1 = 0;
	int num2 = 0;

	char operation = 0 ;
	char operation2;
	int total = 0;
	
	/*modular is q while m is multiplication*/
	printf(" Programming Assignment #2 - by Geoffrey \n");
	printf("\n");
	
	/* asking user for one input*/
	printf("please enter the First Number:");
	scanf("%d", &num1);
	fflush(stdin);
	
	/* checks if the first user input is within range( bounds checking)*/
	while (num1 < -1000 || num1 > 1000) {
		printf("out of bounds\n");
		printf("please enter the First Number:");
		scanf("%d", &num1);
		fflush(stdin);

	}

	/* ask user for second input*/
	printf("please enter the Second Number:");
	scanf("%d", &num2);
	fflush(stdin);
	
	/* checks if the second user input is within range (bounds checking)*/
	while (num2 < -1000 || num2 > 1000) {
		printf("out of bounds\n");
		printf("please enter the Second number");
		scanf("%d", &num2);
		fflush(stdin);
	}


			
	/* tells user for the next step as prompted*/
	
		printf("Please select an operation to put in the blank space\n");
		printf("%d__%d= \n", num1, num2);
		printf("\n\n");
		printf("type the associated letter and press enter:\n");
		printf(" A - Addition\n S - Subtraction\n M - Multiplication\n D - Division\n Q - Modular\n");

		/* use scanf to receive the letter for the operation*/
		scanf("%c", &operation2);
		fflush(stdin);
				
	/* uss a switch case structure to use the user input with the math operations */
	

		switch (operation2) {
			case 'a':
			case 'A': total = num1 + num2;
					operation = '+';
					
			break;

			case 's':
			case 'S': total = num1 + num2;
					operation = '-';

			break;

			case 'm':
			case 'M': total = num1 + num2;
					operation = '*';

			break;

			case 'd':
			case 'D': total = num1 + num2;
					operation = '/';

			break;

			case 'q':
			case 'Q': total = num1 + num2;
					operation = '%';

			break;

			default: printf("Invalid Letter selected\n");

		}

	printf("RESULT: %d %c %d = %d\n", num1, operation, num2, total);


			
	return(0);
}

Hey...make your self having a good habit of Asking the question in right way (specially in ONLINE forums), and follow who gave you the Answer, and address him, add reputations to him...Thank Him, Not ALL who misguided you. I not only gave you the answer, but i also educated you in your Question. This is very bad..You are asking help....and not following who is writing to you...very bad. Next time you won't get Answers. if you are like this.

also fflush(stdin) is the only way my teacher taught us how to make user inputs and the enter stroke key work together.

A blind guiding the blinds your teacher is.
fflush(stdin) invokes an undefined behaviour. If you don't know what that means, research it. Then ask a pertinent question to your teacher.

Edited 7 Years Ago by Aia: n/a

This question has already been answered. Start a new discussion instead.