Hello!
I am having a difficult time building this program, it is our first time using loops and our professor didnt spend a lot of time going over it. We spent the class transferring a for loop to a while, which did help me see what the function looks like, but being able to incorporate it is a different story! Please someone look at what I have here and try and help me build this!(Not a HW Grade, dont worry)
" OVERVIEW
Scientists will often write programs to perform calculations on some experimental observations,
such as the amount of rainfall or the miles per gallon (mpg) achieved by various cars. In this lab you
are going to practice using loops to calculate the average mpg achieved by a fleet of rental cars.
DEVELOPMENT
You will need to handle 3 pieces of information: Make of the car, Model of the car, Number of cars
owned. Then, you will use a “for” loop to input a variable number of decimals representing miles
per gallon for this problem. Then finally, output the average MPG as a decimal to two (2) decimal
points of precision.
Use the following sample to develop your prompts and inputs, with the user input highlighted in
blue. Your prompts and outputs must match these exactly.
Please enter the make and model of the car: Tesla S
Please enter the number of Tesla S(es) owned: 6
Please enter the mpg for each car: 81.2 93.1 72.9 92.4 89.7 88.6
Average MPG for 6 Tesla S(es) = 86.32
***You must use a for loop to solve this problem***"
* I have some work already completed for this word problem, however it is so minimal I feel it not even necessary to add. Here is what I have started of my loop(that is more than likely wrong)
1 2 3 4 5 6
|
double mpg;
int n;
cin >> n;
for (int i=0; i < n; i++) {
cin >> mpg;
}
|