为什么我的 C++ 函数没有被执行?

Why my function in C++ is not being executed?

我有一个 C++ 实验室,问题是这样的:用户应该为 X 输入一个值(X 是举行的测试的数量)。如果 x<15,程序不计算任何东西。如果 X 在 16 和 30 之间,程序应该计算 C=1.0/10.0*(24A),如果 X>30,程序应该计算 C=0.15(24*A)。我的 multiple if 代码有效,但是当我输入 X 的值时,方程没有求解。有人知道吗??

#include<iostream>
#include<cmath>

#define _USE_MATH_DEFINES

using namespace std;

int main()
{
    //variables defined here
    float A, X, C, F;
    //A stands for number of classes scheduled

    //X is for number of tests and C is the modification 

    cout << "This program predicts the number of cars parked at HVCC at any given hour \n";
    cout << "enter a value for A \n";
    cin >> A;

    cout << "enter a value for number of tests X \n";
    cin >> X;

    if (X < 15)
    {
        cout << "No modificatons needed for under 15 tests \n";
    }

    else if (X > 15 && X < 20)
    {
        cout << "Approximation for between 15-30 tests \n";
        C = 1.0 / 10.0 * (24 * A);
        cin >> C;
    }

    else
    {
        cout << "Approximation for more than 30 tests \n";
        C = 0.15 * (24 * A);
        cin >> C;
    }
}

使用 cin 您可以读取用户输入。使用 cout 打印结果:

#include<iostream>
#include<cmath>

#define _USE_MATH_DEFINES

using namespace std;

int main()
{
    //variables defined here
    float A, X, C, F;
    //A stands for number of classes scheduled

    //X is for number of tests and C is the modification 

    cout << "This program predicts the number of cars parked at HVCC at any given hour \n";
    cout << "enter a value for A \n";
    cin >> A;

    cout << "enter a value for number of tests X \n";
    cin >> X;

    if (X < 15)
    {
        cout << "No modificatons needed for under 15 tests \n";
    }

    else if (X > 15 && X < 20)
    {
        cout << "Approximation for between 15-30 tests \n";
        C = 1.0 / 10.0 * (24 * A);
        cout << C; // replace cin >> with cout <<
    }

    else
    {
        cout << "Approximation for more than 30 tests \n";
        C = 0.15 * (24 * A);
        cout << C; // replace cin >> with cout <<
    }
}
cin >> C; will get the user input for C.

在两个 else 块中将其更改为 cout << C