gpt4 book ai didi

c++ - else if 预期表达式 c++/Xcode

转载 作者:行者123 更新时间:2023-11-28 00:16:32 26 4
gpt4 key购买 nike

我在论坛上看到过这个问题,但我无法解决这个问题。毕竟“else if”Xcode 无法编译,它告诉我这是一个“解析问题”并且需要一个“预期表达式”。

我知道这是一个初学者的问题,但我真的很想了解我的代码有什么问题,为什么它在每次 esle 后总是告诉我预期的表达式,如果...


if (TypeStrat == 1)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixCall(S,K,T,r,v) + BSPrixPut(S,K,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K,T,r,v) + BSDeltaPut(S,K,T,r,v)) << endl;
cout << "Vega " << (2*BSVega(S,K,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K,T,r,v) + BSRhoPut(S,K,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K,T,r,v)/365.0) + (BSThetaPut(S,K,T,r,v)/365.0)
<< "journalier" << endl;

else if (TypeStrat == 2)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) + BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) + BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) + BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) + BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) + (BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

else if (TypeStrat == 3)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du short Call ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) - BSPrixCall(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) - BSDeltaCall(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) - BSRhoCall(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) - (BSThetaCall(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

else if (TypeStrat == 4)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du short Put ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - (BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

else if (TypeStrat == 5)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Call ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) - 2*BSPrixCall(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) - 2*BSDeltaCall(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) - 2*BSRhoCall(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) - 2*(BSThetaCall(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

else if (TypeStrat == 6)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Put ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - 2*BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - 2*BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - 2*BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - 2*(BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

}

最佳答案

else if 需要前面的 if 语句。在您的第一个 else if 之前的 if 语句 block 未关闭,即缺少结束大括号 }。此外,最后还有一个额外的 }

缺少大括号:

if (TypeStrat == 1)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixCall(S,K,T,r,v) + BSPrixPut(S,K,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K,T,r,v) + BSDeltaPut(S,K,T,r,v)) << endl;
cout << "Vega " << (2*BSVega(S,K,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K,T,r,v) + BSRhoPut(S,K,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K,T,r,v)/365.0) + (BSThetaPut(S,K,T,r,v)/365.0)
<< "journalier" << endl;

// } <-- Insert ending curly brace here
else if (TypeStrat == 2)

额外的花括号:

else if (TypeStrat == 6)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Put ?" << endl;
cin >> K2;

cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - 2*BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - 2*BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - 2*BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - 2*(BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

} // <-- Remove this extra curly brace

关于c++ - else if 预期表达式 c++/Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29944390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com