程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> before-C++中的這個問題怎麼解決

before-C++中的這個問題怎麼解決

編輯:編程綜合問答
C++中的這個問題怎麼解決

#include
int main()
{
int base, exponent;
std::cout << "Please enter the base and the exponent :" << std::endl;
std::cin >> base >> exponent;
long result = 1;
if (base == 0 && exponent == 0)
{
result = 0;
std::cout << "the " << exponent << " power of "
<< base << " is " << result;

}
else if (base == 0 && exponent != 0)
{
result = 0;
std::cout << "the " << exponent << " power of "
<< base << " is " << result;
}
else if (base != 0 && exponent == 0)
{
result = 1;
std::cout << "the " << exponent << " power of "
<< base << " is " << result;
}
else

{}
if ( exponent < 0)
std::cout << " Exponent can't be smaller than 0." << std::endl;
else
{
for (int i = 1; i <= exponent; i++)
result = result * base;
std::cout << "the " << exponent << " power of "
<< base << " is " << result;
std::cout << std::endl;
}
}
return 0;
}

這是怎麼回事,為什麼會出現這種情況?
[Error] expected unqualified-id before 'return'
[Error] expected declaration before '}' token

最佳回答:


你多了一個}。根據你代碼的意思,應該是else下一個空的{}中的}應該不要吧

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved