Thread: Problem with '=' Operand.. Please help!

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    Question Problem with '=' Operand.. Please help!

    The following code has 16 errors of the same type: error C2106: '=' : left operand must be l-value

    The errors are found within points //A and //B.

    Could someone show me how to overcome these errors?

    Code:
    /*	LEARN ARITHMETICS is a program designed to train one in arithmetic operations by assigning questions
    	to the user and giving output depending on whether the answer is right or wrong. */
    #include<stdio.h>
    #include<stdlib.h>
    void randomNumbers();
    int main()
    {
    	int one;
    	int two;
    	int three;
    	int four;
    	int five;
    	int anOperator, pAnswer, uAnswer, grade;
    	char signOperator;
    	printf("LEARN ARITHMETICS\nTo begin;\n\tEnter 1 for Addition\n\tEnter 2 for Subtraction\n\tEnter 3 for Multiplication\n\tEnter 4 for Division\n\tEnter 5 for All\n");
    	scanf("%d", &anOperator);
    	printf("Enter your grades;\n\t1 for Grade one\n\t2 for Grade two\n\t3 for Grade three");
    	scanf("%d", &grade);
    	if (grade == 1) //A
    		one = (rand() % 10) & two = (rand() % 10) & three = (rand() % 10) & four = (rand() % 10) & five = (rand() % 10);
    	else if (grade == 2)
    		one = (rand() % 100) & two = (rand() % 100) & three = (rand() % 100) & four = (rand() % 100) & five = (rand() % 100);
    	else one = (rand() % 1000) & two = (rand() % 1000) & three = (rand() % 1000) & four = (rand() % 1000) & five = (rand() % 1000);
    	do
    	{
    		if (anOperator == 1)
    			pAnswer = one + two & signOperator = '+';
    		if (anOperator == 2)
    			pAnswer = one - two & signOperator = '-';
    		if (anOperator == 3)
    			pAnswer = one * two & signOperator = '*';
    		if (anOperator == 4)
    			pAnswer = one / two && signOperator = '/'; //B
    		pAnswer = ((((one / two) * three) + four) - five) && (printf("%d / %d * %d + %d - %d = ?", one, two, three, four, five));
    		printf("%d %c %d = ? (Enter the correct value)\n", one, signOperator, two);
    		scanf("%d", &uAnswer);
    		if (uAnswer = pAnswer)
    			printf("Keep up the good work\n");
    		printf("No. Please try again\n");
    	}
    	while (uAnswer = pAnswer || uAnswer != pAnswer);
    	return 0;
    }
    The above program is unfinished.
    Last edited by blacklesness; 11-18-2009 at 03:20 AM. Reason: Addition of new info.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What are these supposed to do?
    one = (rand() % 10) & two = (rand() % 10) & three = (rand() % 10) & four = (rand() % 10) & five = (rand() % 10);
    one = (rand() % 100) & two = (rand() % 100) & three = (rand() % 100) & four = (rand() % 100) & five = (rand() % 100);
    one = (rand() % 1000) & two = (rand() % 1000) & three = (rand() % 1000) & four = (rand() % 1000) & five = (rand() % 1000);
    pAnswer = ((((one / two) * three) + four) - five) && (printf("%d / %d * %d + %d - %d = ?", one, two, three, four, five));
    Last edited by Elysia; 11-18-2009 at 06:31 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    The error is not in the if statement but the immediate staement following it.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    @Elysia Well, the program is meant test one's mathematical aptitude by letting them choose operators then grade levels i.e. Choose '+' then 2. This means the user will have to solve a sum with the addition operator and the operands will have two digits. If he chooses '/' then 3, three digit figures will appear for division calculations.
    (rand() %10) generates a randon number within 1 - 9 ie one digit figure
    (rand() %100) generates a randon number within 1 - 99 ie two digit figure
    (rand() %1000) generates a randon number within 1 - 999 ie three digit figure

    pAnswer is the answer generated by the program that will be compared to that input by the user 'uAnswer'.



    @BEN10 could you be more specific please?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The problem is that what you have written is wrong (it won't compile), so I am unsure of what you actually meant to write on those lines.
    For example, what is this supposed to do?
    ((((one / two) * three) + four) - five) && (printf("%d / %d * %d + %d - %d = ?", one, two, three, four, five));

    What did you intend the program to do with the line?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    I'm not sure what you think & does, but it's not what you think. & is bitwise AND when given two operands.

    Perhaps you are trying to condense multiple assignments into a single line. If so the correct operator is ',', but you do not what to use it here. Just use a block and have each assignment on a separate semicolon terminated line.
    Last edited by King Mir; 11-20-2009 at 08:56 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    I have seen what is wrong with this code hence i'll close this thread. Thanks for your help everyone... :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM