有人可以請解釋我在這段代碼中的上述錯誤?我在CodeBlocks中獲得它,當我使用Visual Studio時,它表示期待一個聲明。 非常感謝。其他沒有以前如果錯誤在c + +
#include <iostream>
using namespace std;
int main()
{
char fruits;
float sales;
cout << " Enter the First letter of the Fruit's name : ";
cin >> fruits;
cout << " Enter the amount of sales : ";
cin >> sales;
if (fruits == 'A' || fruits == 'a')
cout << " You are selling Apples ";
cout << " Your commission is " << sales*(4.5/100) << " rupees. ";
else if (fruits == 'P' || fruits == 'p')
cout << " You are selling Pears";
cout << " Your commission is " << sales*(5/100) << " rupees. ";
else if (fruits == 'O' || fruits == 'o')
cout << " You are selling Oranges ";
cout << " Your commission is " << sales*(5.5/100) << " rupees. ";
else if (fruits == 'G' || fruits == 'g')
cout << " You are selling Grapes ";
cout << " Your commission is " << sales*(6/100) << " rupees. ";
else
cout << " Invalid Entry. Try again. ";
return 0;
}
如何製作包含多個語句的塊?如果你不知道,你需要回到你的書,並從頭開始閱讀。 –
C++不是Python,你知道嗎? – 2014-03-12 16:10:20
這就好像有人在這裏爲Apple工作,不是嗎?缺少大括號連接到水果..至少在這裏,它會導致編譯器錯誤,而不是[goto失敗](http://nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-goto-fail -apples-ssl-bug-explained-plus-an-unofficial-patch /)運行時錯誤。 – stefan