#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下一個空的{}中的}應該不要吧