I am a beginner (very much so) in computer programming, I use a gcc compiler.
The following program is not yet finished, but is at a stage that it should atleast run. It compiles fine, and asks for, and execpts value "b", but then geves a segmentation error message, and I have no idea why. Any help would be appretiated.
[code=cpp]
#include<iostre am>
#include<iomani p>
using namespace std;
double get_input (char note[], double min);
//Requires: A name of the item.
//Promises: "a" (a weight to length ratio).
double calc_a (double b, double l, double g);
//Requires: Previously calculated "a".
//Promises: Total a of cable.
int main()
{
cout<<"main"<<e ndl;
double b=get_input("b" ,0);
double l=get_input("l" ,2*b);
double g=get_input("g" ,0);
double a=calc_a(b,l,g) ;
cout<<"a is_"<<a<<endl;
}
double get_input (char note[],double min)
{
cout<<"input "<<note<<en dl;
cin>>note;
return 1;
}
double calc_a (double b, double l, double g)
{
double a = get_input("g",0 );
while ((l*a-g*(pow(1+a,b)-1))!=0)
{
a=(a-(l*a-g*(pow(1+a,b)-a)))/(l-g*b*(pow(b+1,b-1)));
}
return a;
}[/code]
The following program is not yet finished, but is at a stage that it should atleast run. It compiles fine, and asks for, and execpts value "b", but then geves a segmentation error message, and I have no idea why. Any help would be appretiated.
[code=cpp]
#include<iostre am>
#include<iomani p>
using namespace std;
double get_input (char note[], double min);
//Requires: A name of the item.
//Promises: "a" (a weight to length ratio).
double calc_a (double b, double l, double g);
//Requires: Previously calculated "a".
//Promises: Total a of cable.
int main()
{
cout<<"main"<<e ndl;
double b=get_input("b" ,0);
double l=get_input("l" ,2*b);
double g=get_input("g" ,0);
double a=calc_a(b,l,g) ;
cout<<"a is_"<<a<<endl;
}
double get_input (char note[],double min)
{
cout<<"input "<<note<<en dl;
cin>>note;
return 1;
}
double calc_a (double b, double l, double g)
{
double a = get_input("g",0 );
while ((l*a-g*(pow(1+a,b)-1))!=0)
{
a=(a-(l*a-g*(pow(1+a,b)-a)))/(l-g*b*(pow(b+1,b-1)));
}
return a;
}[/code]
Comment