Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Scripting and Programming Foundations Exam - Topic 4 Question 16 Discussion

A program calculates the average miles per gallon given miles traveled and gas consumedHow should the item that holds me miles per gallon be declared?
B) Variable float milesPerGallon
A) Constant float milesTraveled
C) Variable float milesTraveled
D) Constant float milesPerGallon

WGU Scripting and Programming Foundations Exam - Topic 4 Question 16 Discussion

Actual exam question for WGU's WGU Scripting and Programming Foundations exam
Question #: 16
Topic #: 4
[All WGU Scripting and Programming Foundations Questions]

A program calculates the average miles per gallon given miles traveled and gas consumed

How should the item that holds me miles per gallon be declared?

Show Suggested Answer Hide Answer
Suggested Answer: B

In a program that calculates the average miles per gallon based on miles traveled and gas consumed, the item that holds the miles per gallon should be declared as a variable because it will change depending on the input values. The data type should be a floating-point number (float) because miles per gallon is a value that can have a fractional part, and it is not a fixed value, hence it should not be a constant.


Best practices in programming suggest using variables for values that change and constants for values that remain the same throughout the program execution.

The concept of variables and data types is fundamental in programming and is covered in foundational programming documentation and textbooks.

Contribute your Thoughts:

0/2000 characters
Catrice
4 days ago
This reminds me of a practice question where we had to declare variables for calculations. I feel like B makes the most sense.
upvoted 0 times
...
Cristy
9 days ago
I'm not entirely sure, but I remember something about constants being used for fixed values.
upvoted 0 times
...
Francine
14 days ago
I think it should be a variable since the miles per gallon can change based on input values.
upvoted 0 times
...

Save Cancel