Results 1 to 6 of 6

Thread: Need help with Quick Basic....

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    1

    Need help with Quick Basic....

    Hey.

    Im take a Computer Science course and I need some (well lots of)help with how do this stuff. Firts of im not sure how to loop this:

    ¦INPUT "please enter two numbers separated by a comma: ", num1, num2
    ¦product = num1 * num2
    ¦PRINT "the product of "; num1; "and "; num2; "is "; product
    ¦END

    And then I need to awnser this:

    Ask the user for his first name and store it in a variable named First$. Ask the user for his last name and store it in a variable name Last$. Have your program print the user’s last name first followed by a comma, then his first name to the screen.

    And finaly theres this:

    Workers at a factory work between 20 and 40 hours per week. They are paid using a rate class. If the rate class is an “A”, the worker makes $10 per hour. If the rate class is a “B”, the worker makes $14 per hour. If the rate class is a “C”, the worker makes $18 per hour. Ask the user to enter the employee’s name, hours worked and pay class. Calculate the appropriate gross pay. Print to the screen, the workers name, hours worked, rate class and gross pay.

    Any help would be VERY much appreciated, because im really not catching on to this.
    Last edited by Darkist_Knight; Dec 6th, 2003 at 07:47 PM.

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I think this :

    Code:
    INPUT "please enter two numbers separated by a comma: ", num1, num2
    should be something like :

    Code:
    Print "please enter two numbers separated by a comma: "
    Input num1,num2


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    New Member
    Join Date
    Jan 2004
    Posts
    1
    Well, since im taking Programming in basic right now, i have a 98% in the class (best), and my final is next week, ill give you help and heck im bored so ill give you the whole program...lol.

    First one-


    CLS
    'This program asks the user to input their name to be printed
    INPUT "Please enter your first name: ", First$
    SLEEP 1
    INPUT "Please enter your last name: ", Last$
    SLEEP 1
    CLS
    PRINT Last$; ", "; First$
    END

    The basic idea for that is simple, i dont get whats hard about it, its just like your first program just different variables only stringed. The second one is a little more complex, but not much, i dont understand what you mean by rate class, or i would write it up right now for you. Is it 20 hrs Rate A 30 rate b 40 rate c ? It is easy you just need 2 inputs for the hours and name, and an if sturcture, i just dont get if the class is how many they worked, so ie if its an input for that youll need 3 inputs, and the if would be like
    IF hrs>= 20 and hrs<=40 and rate=a then
    let comp=hrs*10

    except you need one for each rate, and i think you understand the 10 and such. prog. in basic is really not difficult at all if you pay attention and read your book or listen to teacher w/e. i was gone for half a week and missed the beginning of a new chapter which was the hardest id say in the book ebcause it was the ifs and suc and we just started learnign complex things and i ended up getting 50/50 on the test, best in the class, and all i did was read the book, didnt ask anyone for help. if you need more, id be happy to answer some questions...

  4. #4
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    cool

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Evan
    cool


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    New Member
    Join Date
    Mar 2004
    Location
    Florida
    Posts
    5
    Darkest_Knight's mental barriers are so familiar to me from my time as a computer lab assistant in the 1970s.

    His first impression is that 3 conditions should be a 3 IF statements. Proper procedure would be an array. I'll avoid the extremely useful DATA statement because Msft dropped it out of Basic 10 years ago, so get used to not having it.

    Also, get into the concept of storing a truth condition into a boolean variable. In many cases (not all!) this produces cleaner and more flexible code than a bunch of complicated IFs.

    I don't have a copy of QuickBasic loaded tho I have QBasic on my DOS disk. My DOS compiler became Visual Basic for DOS which is a superset of QuickBasic that would load almost all QuickBasic programs and emulate many Windows features in DOS.

    [pre]
    'Always use DOUBLE precision for financials. Accountants do
    'not accept the excuse, "The computer rounded the last penny
    'wrong. What's the big deal?"
    DIM Rate#(3)
    Rate#(1)=10
    Rate#(2)=14
    Rate#(3)=18
    {...}
    Good = 0
    While Not Good
    Input "Enter the rate letter, A, B or C = "; RateCh$
    'Trim off any leading or trailing spaces user may enter.
    RateCh$ = Ltrim$(Rtrim$(RateCh$))
    'Get just the left character (if any)
    RateCh$ = Left$(RateCh$,1)
    'Change it to upper case
    RateCh$ = Ucase$(RateCh$)
    'Transfer truth value of condition into boolean var Good
    Good = (RateCh$>"A" and RateCh$<="C")
    Wend
    RateIndex = Asc(RateCh$) - Asc("A") + 1
    {...}
    If Hours#>=20 and Hours# <=40 Then
    PayCheck# = Hours# * Rate#(RateIndex)
    End If
    [/pre]

    Some explanation. Remember this programming slogan, "It is impossible to make a program foolproof because fools are so ingenious." That's why I put protection against bad input. I got most any possibility. I would've put all of that into one line but that would've been hard to read for a beginner.

    The line below the Wend could be also:
    [pre]
    RateIndex = Asc(RateCh$) - 64 'Ascii A is 65
    RateIndex = Instr(RateCh$, "ABC")
    [/pre]

    Another line that could be different is:
    [pre]
    Good = RateCh$>="A" and RateCh$<"C"
    [/pre]

    I put in unnecessary parentheses because languages like C and Pascal require them there. Also, it looks better (--personal opinion, only).
    Last edited by Grad1980; Mar 19th, 2004 at 07:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width