Floating Point: Stack Underflow

This is a discussion on Floating Point: Stack Underflow within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> //cout statement// #include <conio.h> //getch() and clrscr()// #include <string.h> //strcpy()// #include <time.h> //time function// #include <iomanip.h> //decimal ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    72

    Floating Point: Stack Underflow

    Code:
    #include <iostream.h> 	//cout statement//
    #include <conio.h>     	//getch() and clrscr()//
    #include <string.h>		//strcpy()//
    #include <time.h>			//time function//
    #include <iomanip.h>		//decimal formatting//
    
    
    								//function//
    double mycalc(double x, double& y)
    {
    
       y = (-2)*x*x + 3*x + 1;
    
    
    }
    
               					//main part of program//
    int main(void)
    {
    	double start,end,yvalue;
    	time_t t=time(NULL);	//time function//
    
    								//Fowler Statement//
    	cout << setiosflags(ios::right);
    	cout << setw(79) << ctime(&t)<<endl;
    	cout << setw(79) << "Gavinn Niroopan"<<endl;
    	cout << setw(79) << "Mr. Slack"<<endl;
    	cout << setw(79) << "ICS 3MO-A"<<endl;
    	gotoxy(28,9);
    	cout << "Functions and Relations"<<endl;
    	gotoxy(28,10);
    	cout << "~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
    	cout << "Explanation: " <<endl;
    	cout << "\tUsing variables and looping structures display a chart,the"<<endl;
    	cout << "\tfollowing assignment will demonstrate a program structure, code"<<endl;
    	cout << "\tlayout and use logic structures. The program will use data derived"<<endl;
    	cout << "\tfrom a user and date acquired from the system at time of execution."<<endl;
    
    	getch();         		//pause screen//
       clrscr();				//clear screen//
    
       cout << ctime(&t) << endl;
    
       gotoxy(28,3);
    	cout << "Functions and Relations"<<endl;
    	gotoxy(28,4);
    	cout << "~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<endl;
       cout << "What is the beginning reference in the range of  (-.2.5 to 3.5) - ";
       cin >>start;
       cout << "What is the ending reference in the range of  (-.2.5 to 3.5) - ";
       cin >> end;
    
       clrscr();
    
       cout << ctime(&t) << endl;
    
       gotoxy(28,3);
    	cout << "Functions and Relations"<<endl;
    	gotoxy(28,4);
    	cout << "~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<endl;
    	cout << endl;
       cout <<setw(30)<< " Value of x " << setw(30) << " y = -2x^2 + 3x + 1 " << endl;
       cout <<setw(30)<< " ~~~~~~~~~~ " << setw(30) << " ~~~~~~~~~~~~~~~~~~ " << endl<<endl;
    
       for(start; start<=end; start = start + 0.5)
    
       {
       	mycalc(start,yvalue);
    
          cout << setiosflags(ios::fixed|ios:: right);
          cout << setprecision(1);
          cout << setw(26)<< start << setw(26) <<yvalue<<endl;
    
       }
    
       cout << endl;
       cout <<setw(45)<< "-Thank You-" << endl;
    
    
    
       getch();
    
    
    
    }
    I have a problem with the above code. There is a stack underflow error when i input -2.5 to 3.5. Could i get some help please. Thanks

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    you are not returning anything.

    double mycalc(double x, double& y)

    so
    void mycalc(double x, double&y)

    for(start; start<=end; start = start + 0.5)

    you aren't doing anything with start so:

    for(; start<=end; start += 0.5)

    Those are not causing your problem, just pointing them out.

    I think your problem may simply be mathmatical precidence.

    y = ((-2)*x*x) + (3*x) + 1; // Use parenthesis to specify the proper precidence. Currently it is:

    y= ((-2)*x) * (x +(3 * (X+1)); // Unless this is what you wanted.

    It has been a while since I have played with mathematical precidence, so I may be off a little. The point is it is usually best to use the parenthesis to be explicit.

    Edit: Changed start = start to start+=
    Last edited by bonkey; 10-16-2002 at 02:11 PM.
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  3. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 01:56 AM
  4. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08:14 PM
  5. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 07:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21