Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type Mismach Basic Language

Tags:

basic

I'm a grade 11 student and I am coding in Basic language. I asked the user a question, and the user gets to choose yes or no. In the coding, a "type mismatch" error displayed. Also in the coding, after the question, I coded in some IFs and END IFs, and before I had this problem, it printed 0 when I ran the program.

I'm confused as to why I'm getting a type mismatch, even though my variables in the area of the IFs and END IFs. I have a string with $ at the end as the variable. This is what I have.

A part of the program is supposed to calculate the total insurance of someone renting a car, but the computer needs to know if the user even wants insurance. Even if I say I do want insurance, the program still displays 0 when it outputs the insurance at the end of the program.

So my question is, why am I getting a type mismatch?

Print "Do you want insurance?"
Print "1.Yes"
Print "2.No"
Input strInsurance$
IF strInsurance$=Yes THEN
    strInsurance$=sngDailyInsurance*sngDays
END IF
IF strInsurance$=No THEN
    strInsurance$=0
END IF
like image 713
Student Austin Avatar asked Dec 09 '25 21:12

Student Austin


1 Answers

strInsurance$ is a string variable, so you'd have to surround Yes with quotes, like:

IF strInsurance$="Yes" THEN

And:

IF strInsurance$="No" THEN

Also, you cannot assign a number to a string variable like you do here:

strInsurance$=0

And here:

strInsurance$=sngDailyInsurance*sngDays

It's strange that you reuse the input variable for the result in any case.

like image 151
Miguel Calderón Avatar answered Dec 13 '25 21:12

Miguel Calderón



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!