我正在尝试使用变量中的值作为上限来获取数组中最近的上限(除非找到等效值)的索引,然后在数组中的同一索引处找到该值。size
sum
value
例如:如果 in 的sum
值为 270,我的程序应该找到位于索引 6 in 的值 280size
并输出对应的值value[6]
。
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
double x = 0;
double y = 0;
double sum = 0;
double size[27] = {24, 28, 32, 38, 48, 240, 280, 320, 360, 380,
420, 480, 560, 600, 640, 700, 720, 800, 840,
960, 980, 1120, 1200, 1280, 1440, 1680, 1920};
double value[27] = {.0022, .0026, .0029, .0035, .0044, .0219,
.0256, .0292, .0328, .0384, .0438, .0513,
.0547, .0584, .0641,.0656, .073, .0766,
.0875, .0877, .0897, .1023, .1094, .1169,
.1313, .1531, .175};
cout << "Enter width: " << endl;
cin >> x;
cout << "Enter height: " << endl;
cin >> y;
x = ceil(x) + 3;
y = ceil(y) + 3;
sum = x * y;
}