在线评判错了吗?

时间:2014-02-24 01:03:50

标签: c++

好 正如我一直说我是一名新的C ++程序员 虽然我正在解决简单的问题,以削减我的技能或任何你们称之为... 我面对这种奇怪的事情 网上法官一直给我一个错误的答案......

现在确定我做的一切都是正确的 我调试并使用许多输入,每次我得到正确的输出。

现在我将给你一个简单的代码,我给了我一个包含描述的链接的错误 问题。

让我们从链接开始:http://www.urionlinejudge.com.br/repository/UOJ_1036_en.html 现在代码:

#include <cmath>
#include <iomanip>
#include <iostream>

void Formula(float v1, float v2, float b);

using namespace std;
int main(int argc, char **argv) {
    //making the variables ....
    float a, b, c;
    float v1, v2;

    //reading the variables
    cin >> a >> b >> c;

    //assign v1,v2
    v1 = (pow(b, 2) - (4 * a * c));
    v2 = 2 * a;

    //making sure that i can use V1 , V2
    if (v1 < 0 || v2 == 0) {
        cout << "Impossivel calcular" << endl;
    } //end of the if condition .....
    else {
        //at this condition i will call a function that calculate the square root(s)
        Formula(v1, v2, b);
    } //end of the else condition

    return 0;
} //end of the main method.....

//////////////////////////
//////////////////////////
//////////////////////////

//making the methods
void Formula(float v1, float v2, float b) {
    //first square root...
    float result = -b + sqrt(v1);
    result /= v2;
    cout << "R1 = " << fixed << setprecision(5) << result << endl;
    //second square root ...
    result = -b - sqrt(v1);
    result /= v2;
    cout << "R1 = " << fixed << setprecision(5) << result << endl;
} //end of the method .....

这是最简单的例子...... 现在它可能是我的错误因为我是C / C ++的新手 并且如果有什么不对劲请 告诉我,在大多数情况下,我应该尝试哪些最佳输入?

1 个答案:

答案 0 :(得分:2)

void Formula(float v1, float v2, float b) {
    //first square root...
    float result = -b + sqrt(v1);
    result /= v2;
    cout << "R1 = " << fixed << setprecision(5) << result << endl;
    //second square root ...
    result = -b - sqrt(v1);
    result /= v2;
    cout << "R1 = " << fixed << setprecision(5) << result << endl;
} //end of the method .....

将第二个R1 =修改为R2 =