LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert from string to number

Solved!
Go to solution

Hi everoyne, I need to make a simple program calculating the GPA in 5 classes. Where A,B,C,D,F are the inputs for each one..

 

Here's what I did so far.

Untitled.png

 

But it seems that it's not recognizing when I assign numeric values for each letter. So I'd appreciate any help. I tested for the output of "GP" and input CT=A (4). The answer for GP should be 4x3=12. But I get a number way off that.

I'm fairly new to Labview so sorry if it's a dumb question.

-Daniel

0 Kudos
Message 1 of 6
(3,256 Views)

Attach an actual VI with values saved in the controls by default.

 

I don't see how you are taking a string character and mulitplying it by a number to get a grade point value.  It doesn't make sense.

0 Kudos
Message 2 of 6
(3,253 Views)

Here's the whole problem:

 

Create a program that calculates the GPA of a semester with 5 classes.

Control theory (3 credits)

Digital Signal Processing (3 credits)

Linear Systems (3 creits)

Directed Independent Study (2 credits)

Control System Lab (1 credit)

 

The input is either A,B,C,D, or F and the GPA is a number from 0 to 4.

 

I attached the program that I made.

0 Kudos
Message 3 of 6
(3,244 Views)

You've got numerous problems.

 

1.  Why are you using the Mathscript node?  I thought you were supposed to be doing this in LabVIEW.  A Mathscript node is not real LabVIEW programming.

2.  Why is your result output an array?  Result is computed as a scalar within the program.

3.  How do you expect to go from a letter grade such as A into a numerical grade?  Your A=4 certainly doesn't do it which just assigns the value 4 to a variable called A.

4. Your actual code takes a string which might have the character "A" within it.  When you multiply that by 3, you certainly are going to get any kind of value.

 

If you were trying to write this code in a text language such as BASIC, it would fail just as badly.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 4 of 6
(3,229 Views)
Solution
Accepted by topic author tadm123

I would make an array of clusters.  Each item in the array corresponds to a single course.  Inside of the cluster, I would have a string for the course name, an enum for the grade, and a numeric for the number of credit hours.  Use an enum for the grade so you can make sure the user only puts in the values you want to allow plus the enum is actually a number.  No real conversion needed.  Then you just use a FOR loop (autoindexing) with some shift registers to keep your totals and then divide the grade totals by the credit hours.

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(3,129 Views)

Thank, I didn't know that about "Enum" function, now it's working. Again thanks a lot.

-Daniel

0 Kudos
Message 6 of 6
(3,103 Views)