gpt4 book ai didi

c++ - 函数在经过 while 循环时不更新变量

转载 作者:行者123 更新时间:2023-11-30 05:37:10 24 4
gpt4 key购买 nike

<分区>

#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;
//resistivity ohms*meters
/*
*
*/
double diameter (double wiregauge)
{
double k;
double diam;

k=((36-wiregauge)/39);
diam=(.127)*(pow(92,k));
diam=(diam/100);

return diam;
}
double copperWireResistance(double length, double wiregauge)
{
const long double PI=(atan(1)*4);
int b; //equals k in the first function
double diam1; //diameter of the wire
double cross_area_copper; //denominator of the equation
double numerator1; //numerator of the equation
double p; //resistivity of copper
double coppWireResistance;

b=((36-wiregauge)/39);
diam1=(.127*pow(92,b));
diam1=(diam1/100);
cross_area_copper=PI*(pow(diam1,2));
p=(1.678*(pow(10,-8)));
numerator1=((4*p)*length);

coppWireResistance=numerator1/cross_area_copper;

return coppWireResistance;

}

double aluminumWireResistance(double length, double wiregauge)
{
const long double PI=(atan(1)*4);
int a;
double diam2;
double numerator2;
double cross_area_alum;
double p1;
double alumWireResistance;

a=((36-wiregauge)/39);
diam2=(.127*pow(92,a));
diam2=(diam2/100);
cross_area_alum=(PI*pow(diam2,2));
p1=(2.82*pow(10,-8));
numerator2=((4*p1)*length);

alumWireResistance=numerator2/cross_area_alum;

return alumWireResistance;
}


int main(int argc, char** argv) {

double Max_N; //maximum wire gauge value
double L; //Length of the wire
double string_gauge=0;

cout<<"Maximum wire gauge value: ";
cin>>Max_N;
cout<<"Length of Wire: ";
cin>>L;


while(string_gauge<Max_N)
{
cout<<"String Gauge: "<<string_gauge<<endl;
cout<<"Diameter of wire: "<<diameter(string_gauge)<<endl;
cout<<"Copper Wire Resistance: "<<copperWireResistance(L,string_gauge)<<endl;
cout<<"Aluminum Wire Resistance: "<<aluminumWireResistance(L,string_gauge)<<endl;


string_gauge++;
cout<<endl;
}



return 0;
}

我试图让铜线电阻和铝线电阻在循环运行时更新,但在第一个数字之后它不会更新到新的线规。有什么理由或我需要补充什么吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com