Если я правильно понял, то:
#include <iostream>
int main()
{
using Type = double;
auto function = []() -> Type
uint8_t
a{ 0 },
b{ 0 };
Type accumulate{ 0 };
for (uint8_t i = 1; i <= 30; ++i)
if (i & 1) // isEven
accumulate += (i / 2) - ((static_cast<Type>(i) - 1.2));
else
accumulate += ((static_cast<Type>(i) + 1.2) - i);
// debug std::cout << static_cast<int>(i) << " : " << accumulate << std::endl;
}
return accumulate;
};
std::cout << std::endl << "Result = " << function() << std::endl;
Если я правильно понял, то:
#include <iostream>
int main()
{
using Type = double;
auto function = []() -> Type
{
uint8_t
a{ 0 },
b{ 0 };
Type accumulate{ 0 };
for (uint8_t i = 1; i <= 30; ++i)
{
if (i & 1) // isEven
accumulate += (i / 2) - ((static_cast<Type>(i) - 1.2));
else
accumulate += ((static_cast<Type>(i) + 1.2) - i);
// debug std::cout << static_cast<int>(i) << " : " << accumulate << std::endl;
}
return accumulate;
};
std::cout << std::endl << "Result = " << function() << std::endl;
}