【问题标题】:Need some help on this problem to merge these two codes在这个问题上需要一些帮助来合并这两个代码
【发布时间】: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 不要输入逗号。

标签: c++ c++11 clion


【解决方案1】:

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

A 0 3.13

您的代码读取三个输入:

  1. char c
  2. int n
  3. float x

    读这个: https://www.geeksforgeeks.org/cin-in-c/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 1970-01-01
    • 2020-08-06
    • 2018-05-25
    • 2020-08-06
    • 2019-05-12
    • 1970-01-01
    相关资源
    最近更新 更多