473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

segmentation fault

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.


Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. double get_input (char note[], double min);
  6. //Requires: A name of the item.
  7. //Promises: "a" (a weight to length ratio).
  8.  
  9. double calc_a (double b, double l, double g);
  10. //Requires: Previously calculated "a".
  11. //Promises: Total a of cable.
  12.  
  13. int main()
  14. {
  15.   cout<<"main"<<endl;
  16.   double b=get_input("b",0);
  17.  
  18.   double l=get_input("l",2*b);
  19.  
  20.   double g=get_input("g",0);
  21.  
  22.   double a=calc_a(b,l,g);
  23.   cout<<"a is_"<<a<<endl;
  24. }
  25.  
  26. double get_input (char note[],double min)
  27. {
  28.   cout<<"input "<<note<<endl;
  29.   cin>>note;
  30.   return 1;
  31. }
  32. double calc_a (double b, double l, double g)
  33. {
  34.   double a = get_input("g",0);
  35.   while ((l*a-g*(pow(1+a,b)-1))!=0)
  36.     {
  37.       a=(a-(l*a-g*(pow(1+a,b)-a)))/(l-g*b*(pow(b+1,b-1)));
  38.     }
  39.   return a;
  40. }
Feb 23 '08 #1
5 1040
sicarie
4,677 Expert Mod 4TB
You do know that you are trying to use a function that you haven't defined yet, right? I'm referring to pow(), when you haven't included the cmath library?

Hmm, so I haven't seen get_input() before (or if I has, it was a very long time ago), why not just use cin?
Feb 23 '08 #2
Thanks for the speedy reply. I think I got it figured out.
Feb 23 '08 #3
I'm just trying to learn how to use functions.
Feb 23 '08 #4
sicarie
4,677 Expert Mod 4TB
Thanks for the speedy reply. I think I got it figured out.
Awesome, care to post what you figured out, just in case someone else has the same issue?
Feb 23 '08 #5
I re-wrote it completely, and the only thing that I can see that is different is the boolean expression after the while statement, and also my calc_a formula was wrong.
Feb 23 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script...
3
by: diyanat | last post by:
i am writing a cgi script in C using the CGIC library, the script fails to run, i am using apache on linux error report from apache : internal server error Premature end of script headers:...
16
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
6
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.