Wednesday, September 14, 2016

Variable types

10. Compare and contrast the four primary variable types (bool, int, char, double) we’ve discussed so far. When would you use each, and to store what sort of data?


The four primary variable types are booleans, integers, characters, and doubles. Booleans are true and false statements and when you input them you have to give back a true or false for example when using a boolean you would set up a variable and when the code runs it should run true if it works correctly or false if the statement is incorrect. Integers are numbers preferably smaller numbers and always whole numbers. Characters or Chars are single letters, they can't do full length words but they can be used as shortcuts for words such as Y for Yes or N for No.The double variable holds extremely large numbers like 999999999 and extremely small numbers such as .502.

You would use booleans to set a statement as one state or the other they cant have more than the two options like 8<10 return true it would return true of course. Integers are used anywhere that simple numbers are necessary like for listing numbers.Chars can be assigned to other variables like integers like C=6. Doubles are like integers but are set to numbers like decimals which ints cant reach.

No comments:

Post a Comment