为什么我输入Y或者N的时候会是这样?
现在正在下雨现在正在下雨吗
(Y/N)
#include
using namespace std;
int main()
{
char a;
int b;
while (a=1) {
cout << "现在正在下雨吗" << '\n' << "(Y/N)" << endl;
cin >> a;
switch (a) {
case 'Y':
cout << "现在正在下雨";
a = 2;
break;
case'N':
cout << "现在没有下雨";
a = 2;
break;
default:
a = 1;
}
}
return 0;
}
// Q695122.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
char a = '1';
int b;
while (a=='1') {
cout << "is raining now?" << '\n' << "(Y/N)" << endl;
cin >> a;
switch (a) {
case 'Y':
cout << "raining";
a = '2';
break;
case'N':
cout << "not raining";
a = '2';
break;
default:
a = '1';
}
}
return 0;
}
while (a=1)
->
while (a==1)
while (a=1)
->
while (a=='1')
a = 2;
->
a = '2';
a = 1;
->
a = '1';
char a;
->
char a = '1';
while(a=1)会始终为真,应该是a==1吧