【发布时间】:2022-11-22 06:14:49
【问题描述】:
#include <iostream>
using namespace std;
int main()
{
char c;
int n;
cout << " Please enter a letter of the Alphabet and a decimal number";
cin >> c >> n;
if (c == 'a'|| c== 'e'|| c== 'i'|| c== 'o'|| c== 'u'||c == 'A'|| c== 'E'|| c== 'I'|| c== 'O'|| c== 'U' )
{
cout << c << " is a vowel" << endl;
}
else
{
cout << c << " is a consonant" << endl;
}
float x;
cin >> x;
if (x<0)
cout << x << " is less than 0";
else if (x>0&&x<100)
cout << x << " is in range ";
else
cout << x << " is out of bounds";
return 0;
}
输入 A, 41.5 时的输出是这样的:
A是元音 nan 超出范围。
我希望代码能够找到这两个问题的答案,并告诉我它是否低于 0、在范围内或超出范围,还说该字母是元音字母还是辅音字母,我怎么能去关于这样做?
【问题讨论】:
-
摆脱
int n;和使用它的代码。 -
That and 不要输入逗号。