为什么C没有从结构中获取价值

Why C is not taking value from structure?

本文关键字:获取 结构 为什么      更新时间:2023-10-16

我创建了结构并给出了负载C和G的值。我希望用户输入荷载,它必须与结构中的荷载之一匹配。然后,应取相应负载的C和G值进行进一步计算。我的问题是,每当我输入例如 1 的负载时,它必须将 C 的值作为 38,而是需要2293652。即使我输入其他负载值,它仍然需要相同的值。我来自机械背景,所以不要对我太苛刻

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
using namespace std;
struct hook{
    float SL;
    int C;
    int G;
};
struct hook h[]={
    {0.5, 27, 14},
    {1, 38, 20},
    {2, 53, 27},
    {3.2, 68, 35},
    {5, 85, 42},
    {8, 107, 55},
    {10, 119, 60},
    {12, 134, 68},
    {16, 151, 76},
    {20, 169, 80},
    {25, 189, 90},
    {32, 207, 100}
};
int main()
{
    float SL1;
    int C1, G1;
    cout << "Enter the safe working load:n" << endl;
    cin >> SL1;
    int i;
    i >=0;
    for (i=0; i < sizeof h /sizeof *h; i++){
        if(h[i].SL == SL1){
            h[i].C = C1;
            h[i].G = G1;
            break;
        }
    }
    float H=0.93*C1, M=0.6*C1, Z=0.12*C1;
    cout << C1 << endl;
    return 0;
}

不应该这些"h[i]吗?C = C1;" 反过来??

看来这就是问题所在! :O