提问者:小点点

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


我有一个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;
    }
}

共1个答案

匿名用户

使用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 <<
    }
}

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|中|函数|被执行)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?