Register

[CP] Creating a simple program - Print results

Discuss anything related to calculators. For specific help on certain games/programs check the Released Projects subforum.
Member
Posts: 40
Joined: Tue Dec 17, 2013 12:56 pm
Calculators: Casio fx-9860GII, Casio Classpad fx-CP400

[CP] Creating a simple program - Print results

Postby PsySc0rpi0n » Thu Apr 03, 2014 11:38 am

Hi...

I'm trying to make a small program to perform a few calculations but I'm struggling when I want to show the results...

I'm using the Var tab in soft keyboard to save my results in those variables like a, b, c, d, e and so on!

Then I'm also using the built-in funtion solve() to make some calculations.

Then I want t window to pop-up to show the results of solve function but I can't make it work.

The code is:

Code: Select all
...
solve(b=ma + e, e)=>f
Print approx(f)
Pause
solve(0=mx+e, x)=>g
Print approx(g)
Pause
ClrText


The output is showing the first result correctly but the second, "g" is showing a nunmber multiplied by "e".

Any help?

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

Re: Creating a simple program - Print results

Postby helder7 » Thu Apr 03, 2014 4:00 pm

As solve() function return a list, you need to perform a For loop in order to display the results in a pop-up window. Take a look at the sample code below:
You can modify the input just to ask for variable values and use a pre-defined equation formula for exemple...or import existent varibles...

'Define vars as local (optional)
Local a
Local s
Local t
Local i
Local tmp
Local textitle

'User input
Input a,"Equation? (ex: x^2-5=0)"

'Solve the equation
solve(a,x)⇒s

'Display the result
GetType s,t
If t="EXPR"
Then
Message "No solution"
ElseIf t="LIST"
Then
For 1⇒i To dim(s)
ExpToStr i,tmp
StrJoin "Solution ",tmp,textitle
StrJoin textitle,"/",textitle
ExpToStr dim(s),tmp
StrJoin textitle,tmp,textitle
PrintNatural s[i ],textitle
Next
Else
Message "Unknown Error"
IfEnd
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Member
Posts: 40
Joined: Tue Dec 17, 2013 12:56 pm
Calculators: Casio fx-9860GII, Casio Classpad fx-CP400

Re: Creating a simple program - Print results

Postby PsySc0rpi0n » Thu Apr 03, 2014 5:08 pm

Ok, I'll try... I'm new to Casio programming. So i need to know what is EXPR and LIST and what their roles in the program.

Can you help on that?

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

Re: Creating a simple program - Print results

Postby helder7 » Fri Apr 04, 2014 12:28 am

Yes. EXPR and LIST are types of variables. You can check the types of variables and see it's value in "Variable Manager".

Image

The variables used during the program execution are saved in Variable manager (unless they are defined as local, at the beginning of the program).
One advice I give is: during the development of a program use normal variables and change to local variables only when the program is finished. In this way you can easily check variable values and types during the development of a program.
After the program is finished (programmed), the local variables will keep the variable manager clean.

In the sample program, I used the function GetType to get the type (EXPR,LIST,STR,...) of variable s and check if the the solve() has found solutions or no, because when the solved equation has solutions it return a LIST (with values), but when there is no solution it return a EXPR.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Member
Posts: 40
Joined: Tue Dec 17, 2013 12:56 pm
Calculators: Casio fx-9860GII, Casio Classpad fx-CP400

Re: Creating a simple program - Print results

Postby PsySc0rpi0n » Fri Apr 04, 2014 9:49 am

Ok, I think i got it...

I have a small background on programming in C but this is quite different. I need to understand better your lines of code so that i can start trying to write my little program.

My program is the following:

1 - User must input 2 different points (4 coordinates) of a known straight line, like, x1, y1,x2, y2
2 - The program should calculate the slope of that straight line with those 2 points using the expression (y2-y1)/(x2-x1) and show the result.
3 - After the slope calculation, the program should use one of those 2 points to calculate the "b" in the following expression: y=mx + b, where y = y1 or y2, m = slope, x = x1 or x2. (this calculation should use x1 and y1 or x2 and y2, not x1 and y2 or x2 and y1).
4 - Last step is to calculate x, in the general expression y= mx + b, when y=0, m = slope and b = value previously calculated in the step above.

Example:

x1 = 2, y1 = 3
x2 = 1, y2 = -1

Slope
m = (-1-3)/(1-2) = 4

Using x1 and y1, calculate "b"

solve(3 = 4x2 + b, b)
b = -5

Calculate -2x2, when y=0

solve(0=4x - 5,x)
x=1.25

The program should do those simple steps... The final value showed by the program should be x=1.25


PS:
Can I do the following:

Code: Select all
Local tmp
Local slpMess

"Slope Calculus "=>slpMess

Input a, "x1", (strJoin slpMess, "x1")




PS: Ok, i saw I can't do this!

Edit 2;
The PrintNatural s[i],texttitle is giving an "Wrong Argument Type" error!

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

Re: Creating a simple program - Print results

Postby helder7 » Mon Apr 07, 2014 5:14 pm

So the first thing you should do is ask for the 4 points with Input command, and assign that 4 points to the respective variables, like:

Code: Select all
'User input
Input xone,"X1 value?"
Input xtwo,"X2 value?"
...


(yeah ... looks like that the variables x1, x2, etc.. are reserved by the system, but you can use for exemple xone, xtwo...)

As the calculation described in the point 2 is not an equation, you can perform it normally and assign it to a variable, like

Code: Select all
(ytwo-yone)/(xtwo-xone)⇒m


In the point 3, the equation just have a solution or have multiple? If it has always only one solution, you can get the b value doing:

Code: Select all
solve(yone = m*xone + b, b)⇒b
b[1]⇒b


If the equation of the 4th point just have a solution, the way to solve is similar to point 3.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Member
Posts: 40
Joined: Tue Dec 17, 2013 12:56 pm
Calculators: Casio fx-9860GII, Casio Classpad fx-CP400

Re: Creating a simple program - Print results

Postby PsySc0rpi0n » Mon Jun 23, 2014 6:13 pm

Can't I use loop For To Next to ask for a few numbers and then save them in a vector like:

Code: Select all
input x, "How many?",  "Numbers"
For 0 =>i To x-1
input a[i]
Next

For 0=>i To x-1
PrintNatural a[i]
Next


I get an error saying "Domain" and the program stops...

Any help?

Member
User avatar
Posts: 31
Joined: Wed Apr 18, 2012 4:48 pm

Re: Creating a simple program - Print results

Postby Cartix » Sat Jun 28, 2014 2:43 pm

Try to set the dimensions of the list a first
Image

Member
Posts: 40
Joined: Tue Dec 17, 2013 12:56 pm
Calculators: Casio fx-9860GII, Casio Classpad fx-CP400

Re: [CP] Creating a simple program - Print results

Postby PsySc0rpi0n » Sat Sep 06, 2014 4:31 pm

How do I set the size of the list?

Member
User avatar
Posts: 31
Joined: Wed Apr 18, 2012 4:48 pm

Re: [CP] Creating a simple program - Print results

Postby Cartix » Sat Sep 13, 2014 3:49 pm

You should use something like this :
Code: Select all
Seq(1,x-1)=>a
Image

Next

Return to General

Who is online

Users browsing this forum: No registered users and 61 guests