#include // for printf #include // for uint64_t #include "double_from_string.h" const double a_dollar_from_1800_worth[] = { // src: https://www.officialdata.org/us/inflation/1800?amount=1 1.00, // 1800 1.01, 0.85, 0.90, 0.94, 0.93, 0.97, 0.92, 1.00, 0.98, 0.98, 1.04, 1.06, 1.27, 1.40, 1.22, 1.12, 1.06, 1.01, 1.01, 0.93, 0.90, 0.93, 0.83, 0.77, 0.79, 0.79, 0.79, 0.75, 0.74, 0.73, 0.69, 0.68, 0.67, 0.68, 0.70, 0.74, 0.76, 0.74, 0.74, 0.69, 0.69, 0.65, 0.59, 0.60, 0.60, 0.61, 0.65, 0.63, 0.61, 0.62, 0.61, 0.61, 0.61, 0.67, 0.69, 0.67, 0.69, 0.65, 0.66, 0.66, 0.70, 0.80, 1.00, 1.25, 1.29, 1.26, 1.17, 1.13, 1.08, 1.04, 0.97, 0.97, 0.95, 0.90, 0.87, 0.85, 0.83, 0.79, 0.79, 0.81, 0.81, 0.81, 0.80, 0.78, 0.77, 0.75, 0.75, 0.75, 0.73, 0.72, 0.72, 0.72, 0.71, 0.68, 0.67, 0.67, 0.66, 0.66, 0.66, 0.67, 0.67, 0.68, 0.70, 0.71, 0.70, 0.71, 0.75, 0.73, 0.72, 0.75, 0.75, 0.77, 0.79, 0.79, 0.80, 0.87, 1.02, 1.20, 1.37, 1.59, 1.42, 1.33, 1.36, 1.36, 1.39, 1.40, 1.38, 1.36, 1.36, 1.33, 1.21, 1.09, 1.03, 1.06, 1.09, 1.10, 1.14, 1.12, 1.10, 1.11, 1.17, 1.29, 1.37, 1.40, 1.43, 1.55, 1.77, 1.91, 1.89, 1.91, 2.06, 2.10, 2.12, 2.13, 2.13, 2.16, 2.23, 2.29, 2.31, 2.35, 2.37, 2.40, 2.43, 2.46, 2.50, 2.57, 2.65, 2.76, 2.91, 3.08, 3.21, 3.32, 3.52, 3.91, 4.27, 4.52, 4.81, 5.17, 5.76, 6.54, 7.21, 7.66, 7.90, 8.25, 8.54, 8.70, 9.02, 9.39, 9.84, 10.37, 10.81, 11.13, 11.47, 11.76, 12.10, 12.45, 12.74, 12.94, 13.22, 13.67, 14.06, 14.28, 14.60, 14.99, 15.50, 16.00, 16.46, 17.09, 17.03, 17.31, 17.85, 18.22, 18.49, 18.79, 18.81, 19.05, 19.45, 19.94, 20.29, 20.54, 21.51, 23.20 // 2022 }; int main(const int argc, const char* const* argv){ if ((argc != 3) && (argc != 4)){ printf("USAGE: [VALUE] [FROM_YEAR] [TO_YEAR]?\n"); return 1; } unsigned year2 = 2022; if (argc == 4) year2 = double_from_string(argv[3]); const unsigned year1 = double_from_string(argv[2]); const double value = double_from_string(argv[1]); printf("%.2f\n", value * a_dollar_from_1800_worth[year2-1800] / a_dollar_from_1800_worth[year1-1800]); return 0; }