Title: Calculate Age Post by: GarrisonRicketson on April 23, 2011, 12:25:52 pm This is a simple bit of code, but I would like to add a line that calculates the age,and then prints "your age is (age)
Code: DIM name1 AS STRING Title: Re: Calculate Age Post by: GarrisonRicketson on April 23, 2011, 11:23:23 pm Ok, VAL is a new one to me,but thats what it was saying to, cannot convert a string, something like that,... I think this could be used to calculate, pesos / dollars, or other moneys,...and other things too....
thanks from Garry Title: Re: Calculate Age Post by: none on April 24, 2011, 12:11:05 am A picture is worth a thousand words. Try this example and do what it says inside the brackets and then examine the outcome.
Code: DIM name1 AS STRING In the old days of QBasic this would bring about an immediate runtime error. Under QB64 there is no runtime error and the program continues. Obviously unintended input can cause a program to error the result as the above program indicates. The solution for the programmer is the CHECK after each entry and redo it if its wrong. Thats why strings are better. There are built in commands that help convertions. The best solution is whats called a "Filtered input routine". Which means only the correct recognised symbols (either numbers of letters) are allowed to be entered. Incorrect entry is not allowed into the string and not visually shown back. Hence the user presses other buttons to find out what is allow Title: Re: Calculate Age Post by: GarrisonRicketson on April 24, 2011, 12:07:03 pm Ok yea, I see what you mean,....It gave me a 0,....
from Garry Title: Re: Calculate Age Post by: bobostno on April 28, 2011, 10:20:17 am This is my attempt at it, although my error checking is rather outdated.
Code: thedate$ = DATE$ Title: Re: Calculate Age Post by: GarrisonRicketson on April 29, 2011, 07:33:38 am Thant is pretty neat,...all you do is enter the year you were born,...
from Garry Title: Re: Calculate Age Post by: ChatKing on November 21, 2011, 02:36:37 pm simply code for that program is following:-
DIM name1 AS STRING DIM num1 AS INTEGER DIM num2 AS INTEGER INPUT "What is your name"; name1 INPUT "What is the current year"; num1 INPUT "What year were you born"; num2 PRINT name1 PRINT num1 PRINT num2 PRINT num1 - num2 'but this dose not work SLEEP Title: Re: Calculate Age Post by: ChatKing on November 21, 2011, 03:34:04 pm I have a complete code of Calculate Age but there is still a bug, can anybody find out and solve it and tell me. Thanks
Code: DIM YourName AS STRING Title: Re: Calculate Age Post by: GarrisonRicketson on November 21, 2011, 03:58:58 pm Thanks for posting this, I have not tried it yet,..I am right in the middle of something,..but also I am glad to see, I recieve the notices,when you post fine, this will help me respond sooner,..
from Garry Edited: I tried it now, but it seems to be pretty good to me, I did notice one time it asked for the dates twice,...Is, that what you ment by "bug" ? Title: Re: Calculate Age Post by: ChatKing on November 22, 2011, 10:53:14 am Hi to All
Yes GarrisonRicketson, the bug is when you enter something wrong it repeats for the input that is the bug, can anybody tell me the solution. Title: Re: Calculate Age Post by: GarrisonRicketson on November 23, 2011, 10:49:42 pm Hope fully maybe someone can, but I don't know,
from Garry P.S. If you want I could post the code on another forum, and probley get a answer ?,. Title: Re: Calculate Age Post by: GarrisonRicketson on November 25, 2011, 07:48:51 am Well I did post a link to this thread, on qb64.net, and this is what I got, posted by DeeBee at qb64.net The wrong sub should not call start. It should return to start, and after it calls wrong, there should be an evil GOTO to re-ask the value. Also the leap year formula is incorrect, but it will probably work for what they are doing. http://en.wikipedia.org/wiki/Leap_year ----------------------------------- Garry (me) added, I notice he says "evil" goto,.. some people are against useing goto,..but there also are times when it is useful,or even neccessary,... |