c++ do while 循环的小问题


#include <stdio.h>
#include <ctype.h>
int main()
{
    int a;
    char select='y';
    do
    {
        printf("Do you want to play again?(y or n)");
        scanf("%c",select);
    }
    while(toupper(select)=='Y'); 
    return 0;
}

为什么我输入y之后就直接结束程序了,而不是继续循环。


#include<bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

int main()
{
    int a;
    string select;
    while(1)
    {
        printf("Do you want to play again?(y or n)\n");
        cin >> select;
        //cout << select << endl;
   //   if (select != "y") {
     //     cout << 234 << endl;
//      }
        if (select != "y" && select != "y") {
        //    cout<<1<<endl;
            break;
        }
    }
    return 0;
}

是小写y吧?你怎么大写了?

scanf("%c",&select); //取地址别忘了
答快了,不需要&。
——————————————————————————
另外输入的时候,注意大小写。