tags:

views:

248

answers:

1

I wrote a program (on my TI-84 calculator) to satisfy the following exercise:

Write a program that will print all solutions of the inequality ax + b < c, where a, b, and c are entered by the user. In this program the domain of x will be a set of consecutive integers, where the smallest and largest members of the set will also be entered by the user. (Hint: Use a FOR . . . NEXT loop to test each integer from smallest to largest.)

This is the code I have:

:Input "A=",A
:Input "B=",B
:Input "C=",C
:Disp "DOMAIN FOR X"
:Input "MIN=",D
:Input "MAX=",E
:For(X,D,E,1)
:If AX+B<C
:Disp X
:End

I sort of figured it out by chance; I don't really know how 'If' works inside 'For.' I wanted to have it tell me if there is no solution, though, so I tried:

:Input "A=",A
:Input "B=",B
:Input "C=",C
:Disp "DOMAIN FOR X"
:Input "MIN=",D
:Input "MAX=",E
:For(X,D,E,1)
:If AX+B<C
:Then
:Disp X
:Else
:Disp "NO SOLUTION"
:End

But this returns the value for "MIN=" Why is this? Can anyone help me understand these work?

+1  A: 

Perhaps try adding an additional End at the end of the program? As far as I know, you need to have a corresponding End for each For or If, etc.

nasufara
Ah, yes. This will print any solutions and then "NO SOLUTION" for the integers that produce a false statement. How can I make it so if there is at least one solution, it doesn't display the no solution, and if there aren't any solutions at all, it will display the no solution only once?
John
Perhaps use an additional variable, and then set it to 1 if you find a solution, 0 otherwise. Once you get out of the loop, you can check it, and do your stuff from there. I don't have my calculator on me, but I'm sure theres a `Break` command in list somewhere. Just stick that after the `Disp X` in the `If` statement.
nasufara