做下面的代碼和編譯錯誤我不知道了要如何處理這個C ++
#include <iostream>
using namespace std;
int main()
{
double RTinSeries, RTinParallel, R1, R2, R3, R4, R5, R6, Option, Opt1, Opt2;
cout<<"Enter your option:(1 for parallel and 2 for series)";
cin>>Option;
if (Option =< 1 && Option >=3)
{
cout<<"Error!";
cout<<"You've enter a wrong Option";
}
{
else if (Option = 1);
for (Opt1=RTinParallel; RTinParallel = (1/((1/R1)+(1/R2)+(1/R3)+(1/R4)+ (1/R5)+(1/R6))););
cout<<"Your Choice is Parallel";
cout<<"Enter Resistance Value for R1:";
cin>>R1;
cout<<"Enter Resistance Value for R2:";
cin>>R2;
cout<<"Enter Resistance Value for R3:";
cin>>R3;
cout<<"Enter Resistance Value for R4:";
cin>>R4;
cout<<"Enter Resistance Value for R5:";
cin>>R5;
cout<<"Enter Resistance Value for R6:";
cin>>R6;
cout<<"Total Resistance in Parallel is:"<< Opt1<<"ohms"<<endl;
}
{
else (Option = 2);
for (Opt2=RTinSeries; RTinSeries = R1 + R2 + R3 + R4 + R5 + R6;)
cout<<"Your Choice is Series";
cout<<"Enter Resistance Value for R1:";
cin>>R1;
cout<<"Enter Resistance Value for R2:";
cin>>R2;
cout<<"Enter Resistance Value for R3:";
cin>>R3;
cout<<"Enter Resistance Value for R4:";
cin>>R4;
cout<<"Enter Resistance Value for R5:";
cin>>R5;
cout<<"Enter Resistance Value for R6:";
cin>>R6;
cout<<"Total Resistance in Series is:"<<Opt2<<"ohms"<<endl;
}
system("pause");
return 0;
}
而且編譯的結果
9:15: error: expected primary-expression before '<' token
15:7: error: 'else' without a previous 'if'
15:26: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
16:92: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
33:3: error: 'else' without a previous 'if'
34:63: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
我建議讀或在C或C++的基礎知識的基礎課程。你有基本的語法錯誤,你應該學習如何自行修復。 –
'else if(Option = 1);'應該是'else if(Option == 1);'。第一個是轉讓,第二個是測試。 – Galik
以及我已經修復,但我現在得到的錯誤是不同的 –