I have a TI-84 Plus SE and I am learning TI BASIC, your site has been quite helpful to understend some of the potencial of this programming mode, I have a problem with some programm I need to compile in my TI 84SE, it is written in C++ anyway this is the complete code of the program I wish to compile in TI BASIC.... but my problem is in the while loops..



Code:
#include <iostream.h>
#include <conio.h>
#include <math.h>
double f(double x);
void main()
{
   double a,b,I,resp;
   cout << "Program to integrate the function\n";
      cout << "0.2 + 25x - 200x^2 + 675x^3 - 900x^4 + 400x^5, \n";
      cout << "Using Trapecious Simple Rule\n" << endl;
      do
      {
         cout << "\nPlease enter the limits\n";
      cout << "Lower limit:";
      cin >> a;
      cout << "Upper limit:";
      cin >> b;
         cout<<"Are the values correct?(0=yes,1=no)?";
         cin>>resp;
      }while(resp==1);     // FROM HERE ONWARDS IS MY CONFUSION
        I=(b-a)*((f(a)+f(b))/2);
     cout << "\nThe answer is: " << I << endl;
     getch();
}

double f(double x)
{   
          return(0.2+25*x-200*pow(x,2)+675*pow(x,3)-200*pow(x,4)+400*pow(x,5));
}
In TI-BASIC this might be:

Code:
PROGRAM:TRAPECIO
:Disp "PROGRAM TO","INTEGRATE THE","FUNCTION:","0.2 + 25x - 200x^2 + 675x^3 - 900x^4 + 400x^5","Using Trapecious Simple Rule
:Repeat(R=1)
:Disp "ENTER LIMITS
:Input "LOWER:",A
:Input "UPPER:",B
:Disp "CORRECT? 1=Y,0=N
:Input R
:End
:A-->X:prgmZTRAPF:X-->C
:B-->X:prgmZTRAPF:X-->D
:Disp "RESULT:
:Disp (B-A)(.5(C+D
:Pause

PROGRAM:ZTRAPF
:0.2+25X-200X^2+675X^3-200X^4+400X^5-->X


where --> is the [STO>] key.
Instead of this:

Code:
:A-->X:prgmZTRAPF:X-->C
:B-->X:prgmZTRAPF:X-->D

PROGRAM:ZTRAPF
:0.2+25X-200X^2+675X^3-200X^4+400X^5-->X


This would be better:

Code:

:A:prgmZTRAPF:Ans-->C
:B:prgmZTRAPF:Ans-->D

PROGRAM:ZTRAPF
:0.2+25Ans-200Ans[sup]2[/sup]+675Ans[sup]3[/sup]-200Ans^4+400Ans^5


Using Ans and the 2 and 3 from the MATH menu will save a few bytes. (the sup tag doesn't work in the code tag. You should know what it means.) Maybe this:

Code:
:Repeat R=1
:blah blah blah
:End

Could be this:

Code:
:Repeat Ans=92
:blah blah blah
:Disp "CORRECT? 1=Y,0=N
:Repeat getkey=92 or getkey=93
:End
:End

Oh and this:

Code:

:Disp (B-A)(.5(C+D
:Pause

Should be this:

Code:

:Pause (B-A)(.5(C+D

Couldn't resist the urge to optimize. Very Happy

Optimized Version:

Code:

PROGRAM:TRAPECIO
:Disp "PROGRAM TO","INTEGRATE THE","FUNCTION:","0.2 + 25x - 200x^2 + 675x^3 - 900x^4 + 400x^5","Using Trapecious Simple Rule
:Repeat Ans=92
:Disp "ENTER LIMITS
:Input "LOWER:",A
:Input "UPPER:",B
:Disp "CORRECT? 1=Y,0=N
:Repeat getkey=92 or getkey=93
:End
:End
:A:prgmZTRAPF:Ans-->C
:B:prgmZTRAPF:Ans-->D
:Disp "RESULT:
:Pause (B-A)(.5(C+D

PROGRAM:ZTRAPF
:0.2+25Ans-200Ans[sup]2[/sup]+675Ans[sup]3[/sup]-200Ans^4+400Ans^5
More optimizations:


Code:

PROGRAM:ZTRAPF
:.2+25Ans(1+25Ans²-8(Ans-Ans³-2Ans^4


and


Code:

:Pause .5(B-A)(C+D


are a lot better too.
Hi all, after all thanks for your time an pacience. I am kind of new about programming, and programming in TI BASIC in my TI84PLUS SE is being a great experience as well

I put the code in my Graphing Calculator a few seconds.... I don't know if I made a mistake when typing it in the Graphing Calculator , but the programs keeps asking me for the upper and lower limits, when I say yes (chose 1 option) ask me again for the upper and lower limits


Here I show you the screenshots I took:








ANd here is the code of the other programm:




Don't know what is wrong, please help me.. Confused
Change this code to do what is necessary:


Code:
:Repeat getkey=92 or getkey=93
:End


If it's 92, make it exit, otherwise go back and ask again.

Also, you don't need the 0 in a decimal number (such as .5 or .2). That'll save 2 bytes in the whole thing.
Yeah, I purposely did minimal optimizations; I wanted it to be understandable to someone new to TI-BASIC, and I figured we could then work on teaching him optimizing later. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement