1 / 11

CSCI N201 Programming Concepts and Database 7 – Variables, Input and Output Lingma Acheson

CSCI N201 Programming Concepts and Database 7 – Variables, Input and Output Lingma Acheson linglu@iupui.edu. Department of Computer and Information Science, IUPUI. Task:. Ask the user his or her name, and repeat that name to the user E.g. Comp: What is your name? User: Lingma

jsund
Download Presentation

CSCI N201 Programming Concepts and Database 7 – Variables, Input and Output Lingma Acheson

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI N201 Programming Concepts and Database 7 – Variables, Input and Output Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

  2. Task: • Ask the user his or her name, and repeat that name to the user • E.g. • Comp: What is your name? User: Lingma Comp: Hi Lingma!

  3. Input Requires • A question asked by computer • E.g. What is your name? How old are you? Where do you live? How much is two plus two? • An answer to the question • E.g. Lingma 12 Indiana

  4. Output Requires • Output the answer entered by the user • The answer is stored in computer to be used for output. “Lingma” Hi, Lingma! Lingma

  5. Variable • A place in memory to hold things • Like a container • Different containers for different stuff • Need to plan what and how many variables are needed, and create variables first

  6. Variables require: • Name – descriptive • Init – starting value • Type – kind of data (string, numeric) • Purpose – or description • You can't use a variable if you haven't created the variable • Miracle – “What is your name?” • http://www.cs.iupui.edu/~aharris/MirJS.html • http://www.cs.iupui.edu/~aharris/n301/miracleSum.html

  7. String Data • Text • Series of alphanumeric characters • Usually enclosed in quotes (“”) • Size depends on length of text

  8. Numeric Data • Integer (+/-,0, no decimals) • Long Integer • Float (includes decimal values) • Double • Size depends on type of number • Miracle – “How old are you?”

  9. String Concatenation • Technique for combining text • “a” + “b” = “ab” • Frequently uses the plus sign • Can be used to combine variables and literals: • Miracle - “Hi,” + userName + “!”

  10. Inside the Code • Understand the code • function main(){ … } – main structure • // - comments, codes behind this won’t be executed • ;- end of a statement • Code is executed line by line

  11. Play with Miracle • Answer 2 or 3 questions • Output a longer sentence • A simple calculator • Adding two numbers and output the result • Ask the user to enter the first number • Ask the user to enter the second number • Change the first variable to integer • Change the second variable to integer • Add the two variables and store in the third variable • Output – “The result is …”

More Related