I';“我得到了”;错误表达式必须是可修改的左值;在C中

I';“我得到了”;错误表达式必须是可修改的左值;在C中,c,error-handling,C,Error Handling,已经搞乱了一段时间,似乎可以处理好它。有人看到我没有看到的东西吗?Char位于嵌套if语句的最底部,这是主要的问题 谢谢 这些嵌套的if字符给了我问题。小心逻辑比较运算符('=')和矫揉造作运算符('=')。 还要尽量避免scanf(“%C”),尽可能使用string或int,或者使用_getch() 您应该使用=来比较字符,而不是=。一个等号就是赋值。哎呀!!!!!非常感谢你扫描频率(“%c”和&ch1)-->scanf(“%c”和&ch1)使用省略的换行符\n字符。 // This is a

已经搞乱了一段时间,似乎可以处理好它。有人看到我没有看到的东西吗?Char位于嵌套if语句的最底部,这是主要的问题 谢谢


这些嵌套的if字符给了我问题。

小心逻辑比较运算符('=')和矫揉造作运算符('=')。 还要尽量避免scanf(“%C”),尽可能使用string或int,或者使用_getch()


您应该使用
=
来比较
字符,而不是
=
。一个等号就是赋值。哎呀!!!!!非常感谢你<代码>扫描频率(“%c”和&ch1)-->
scanf(“%c”和&ch1)
使用省略的换行符
\n
字符。
// This is a mix of psuedocode and actual C code 
#include "stdio.h" 
#include "conio.h" 
#include "stdlib.h" // rand is in here 
#include "time.h" // contains time structure 
#pragma warning (disable : 4996) // turn off stdio function warnings 


int main(void)
{
time_t t; // a time object for rand seed 

// seed random number generator 
srand((unsigned)time(&t));

// MAIN PROCESSION LOOP 

char ch1;
char ch2;
int get;
int chOK = 0;
do {
    // Get human's move 
        printf("Hey it's your turn!\n choose rock,");
printf(" paper, or scissors and see if you can be me young padawan");
    // character input validation loop 

    do {
        scanf("%c", &ch1);

            switch(ch1)
        {
            case'R':
                break;
            case 'r':
                break;
            case 'P':
                break;
            case 'p':
                break;
            case 'S':
                break;
            case 's':
                break;
            case 27:
                chOK = 1;
                break;
            default :

                chOK = 0;
                    break;
        }
    } while (chOK = 1);

    // Convert input to uppercase 
    // 
    if (ch1 > 'Z') ch1 -= 32;

                // Get computer's move 
                ch2 = rand() % 3; // C code to get a rand # 
                switch (ch2)
                {
                case 0:
            ch2 = 'R';
                    break;
                case 1:
                    ch2 = 'S';
                    break;
                case 3:
                    ch2 = 'P';
                    break;

                }
                // Check who won 
                if (ch1 == 'R' && ch2 == 'R')
                    printf("Rock Rock Draw");
                        if (ch1 = 'R' && ch2 = 'P')
                            printf("Rock Paper Puter");
                        if (ch1 = 'R' && ch2 = 'S')
                            printf("Rock Scissors Human");
                            if (ch1 = 'S' && ch2 == 'P')
                                printf("Paper Paper Draw");
                            if (ch1 = 'P' && ch2 = 'R')
                                printf("Paper Rock Human");
                            if (ch1 = 'P' && ch2 = 'S')
                                printf("Paper Scissors Puter");
                                    if (ch1 = 'S' && ch2 == 'S')
                                        printf("Scissors Scissors Draw");
                                    if (ch1 = 'S' && ch2 = 'P')
                                        printf("Scissors Paper Human");
                                    if (ch1 = 'S' && ch2 = 'R')
                                        printf("Scissor Rock Puter");


                                      } while (ch1 != 27)
// This is a mix of psuedocode and actual C code
#include "stdio.h"
#include "conio.h"
#include "stdlib.h" // rand is in here 
#include "time.h" // contains time structure 
#pragma warning (disable : 4996) // turn off stdio function warnings 


int main(void) {
    time_t t; // a time object for rand seed

// seed random number generator
    srand((unsigned)time(&t));

// MAIN PROCESSION LOOP

    char ch1;
    char ch2;
    int get;
    int chOK = 0;
    do {
        // Get human's move
        printf("\n\nHey it's your turn!\n\n");
        printf("choose rock,paper, or scissors\n");
        printf("and see if you can be me young padawan : ");
        // character input validation loop

        do {
            chOK = 1;
            ch1=_getch();


            switch(ch1) {
                case'R':
                case 'r':
                        ch1='R';
                    break;
                case 'P':
                case 'p':
                        ch1='P';
                    break;
                case 'S':
                case 's':
                        ch1='S';
                    break;
                case 27:
                    break;
            default :
                chOK = 0;
            }

        } while (!chOK);

        printf("%c\n",ch1);

        // Get computer's move
        ch2 = rand() % 3; // C code to get a rand #
        ch2="RSP"[ch2];

        // Check who won
        printf("\n [ ");
        if (ch1 == 'R'){
            if( ch2 == 'R')
                printf("Rock Rock Draw");
            if( ch2 == 'P')
                printf("Rock Paper Puter");
            if( ch2 == 'S')
                printf("Rock Scissors Human");
        }

        if (ch1 == 'P'){
            if( ch2 == 'R')
                printf("Paper Paper Draw");
            if( ch2 == 'P')
                printf("Paper Rock Human");
            if( ch2 == 'S')
                printf("Paper Scissors Puter");
        }

        if (ch1 == 'S'){
            if( ch2 == 'R')
                printf("Scissors Scissors Draw");
            if( ch2 == 'P')
                printf("Scissors Paper Human");
            if( ch2 == 'S')
                printf("Scissor Rock Puter");
        }
        printf(" ]\n");
    } while (ch1 != 27);

    printf("\nProgram terminated\n");
}