Sunday, March 22, 2026

Notes

  

c++ stuff to not forget

data types (the boxes)

  • int - for whole numbers (like how many albums)
  • double - for numbers with decimals (like money: 49.99)
  • bool (true or false)
  • float (similar to double, but less precise. takes less effort to compute!)
  • std::string - for any text or words ("bts", "arel")

remember to name them!
std::string name = "arel"; not std::string = "arel";


operators (the math)

  • + (adds)
  • * (multiplies)
  • / (divides)
  • % (modulo, what's left)
  • = (this one is important, it means "save the answer into...")

so total = price * amount; calculates the math and saves it in total.


cin and cout (talking to the computer)

  • std::cout << : prints stuff onto the screen. arrows point out.
  • std::cin >> : waits for you to type something. arrows point in, to the variable.

possible coding errors

  1. ; : every single instruction needs a semicolon at the end
  2. std:: : goes before cout, cin, string, endl.
  3. std::endl : makes the text jump to a new line on the receipt.
  4. " " : use quotes for words you want to print, but no quotes for variables.
    • std::cout << "total: "; (prints the word total:)
    • std::cout << total; (prints the number saved inside the total variable)

No comments:

Post a Comment