The assignment of the value of the equation to the variable (second line inside the loop) is always less by 1 -on the first iteration only- although the equation (first line inside the loop) on its own calculates fine.
I am using MinGW compiler, codeLite software on a Windows machine.
#include <iostream>
#include <cmath>
#include <vector>
int main(){
std::vector<int> elements_of_num {5, 0, 3};
size_t power = 2;
int n {0};
for(int el: elements_of_num){
std::cout << n + el * pow(10, power) << std::endl;
n = n + el * pow(10, power);
std::cout << n << std::endl;
power--;
}
std::cin >> n;
return 0;
}
Expected result: {500, 500} {499, 499} {503, 503}
Actual result: {500, 499} {499, 499} {502, 502}