11 posts
• Page 1 of 2 • 1, 2
- PsySc0rpi0n
- 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
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:
The output is showing the first result correctly but the second, "g" is showing a nunmber multiplied by "e".
Any help?
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?
- helder7
- 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
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...
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
- PsySc0rpi0n
- 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
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?
Can you help on that?
- helder7
- 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
Yes. EXPR and LIST are types of variables. You can check the types of variables and see it's value in "Variable Manager".

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.

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
- PsySc0rpi0n
- 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
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:
PS: Ok, i saw I can't do this!
Edit 2;
The PrintNatural s[i],texttitle is giving an "Wrong Argument Type" error!
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!
- helder7
- 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
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:
(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
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:
If the equation of the 4th point just have a solution, the way to solve is similar to point 3.
- 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
- PsySc0rpi0n
- 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
Can't I use loop For To Next to ask for a few numbers and then save them in a vector like:
I get an error saying "Domain" and the program stops...
Any help?
- 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?
- PsySc0rpi0n
- 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
How do I set the size of the list?
Re: [CP] Creating a simple program - Print results
You should use something like this :
- Code: Select all
Seq(1,x-1)=>a
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 28 guests