c++ 需要一些关于这个问题的帮助来合并这两个代码

cx6n0qe3  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(1375)
#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,在范围内,或超出界限,还说,字母是一个元音或辅音,我该如何去做呢?

avwztpqn

avwztpqn1#

您的输入不正确。正确的输入示例为:

A 0 3.13

代码读取三个输入:

  1. char c
  2. int n
  3. float x
    请阅读:https://www.geeksforgeeks.org/cin-in-c/

相关问题