Please help!! In a little over my head!
I am continuing an assignment that our class has been working on at home for about a week and have run into a snag. We are learning about loops and this week's installment calls for a more complex program and I am having trouble creating it. Here our the directions and what I have thus far...
A rental car company typically has multiple makes and models in its fleet, and they may
want to repeat the mpg computation for each make and model. Also, in order to prevent
the user from adding erroneous values, your program will need to error check the user’s
inputs to the program.
In this phase you will add two features to your program to accomplish these tasks:
1. Add an outer do-while loop that allows the user to repeat the calculations until
they are done. The user must type y or n (lowercase). If they type anything else,
assume they want to repeat the calculation.
2. Assume that no company owns more than 10 fleet vehicles, so error check the
user’s input to ensure they only enter [1, 10] as the number of vehicles they own.
3. Notice on the sample output that if the user types 1, the (es) is removed when the
average mpg is printed. Use an if statement to ensure this happens with your
program.
Match the following prompts and error messages for your program below.
Please enter the make and model of the car: Tesla S
Please enter the number of Tesla S(es) owned (1-10): -3
*** Error *** Enter a number between 1 and 10 (inclusively).
Please enter the number of Tesla S(es) owned (1-10): 15
*** Error *** Enter a number between 1 and 10 (inclusively).
Please enter the number of Tesla S(es) owned (1-10): 3
Please enter the mpg for each car: 48.2 51.7 62.0
Average MPG for 3 Tesla S(es) = 53.97
Do you want to repeat this computation (y/n)? y
Please enter the make and model of the car: Infiniti G37
Please enter the number of Infiniti G37(es) owned (1-10): 4
Please enter the mpg for each car: 28.0 20.0 16.0 12.0
Average MPG for 4 Infiniti G37(es) = 19.00
Do you want to repeat this computation (y/n)? k
Please enter the make and model of the car: Junker 10
Please enter the number of Junker 10(es) owned (1-10): 1
Please enter the mpg for each car: 5
Average MPG for 1 Junker 10 = 5.00
Do you want to repeat this computation (y/n)? n
***You must use a do-while loop to repeat the computation***
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
using namespace std;
int main()
{
int model_of_car, n;
double sum = 0.0, mpg;
cout << "Please enter the make and model of the car:";
cin >> model_of_car;
cout << "Please enter the number of Tesla(es) owned:";
cin >> n;
cout << "Please enter the mpg for each car:";
cin >> mpg;
for (int i=0; i < n; i++) {
cin >> mpg;
double average = sum/n;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Average MPG for 6 Tesla S(es)";
cin >> mpg;
return 0;
|