Need help to see what I did wrong and/or what am I missing
The formula to compute watts generated per day (represented by w)
w=g(〖s/25)〗^3
where g is the generator’s nameplate capacity (maximum wattage, for example, 3000) and s is the average speed of the wind in miles per hour. Note: this formula is only accurate for wind speeds from 6 to 25 miles per hour inclusive. If 25 < s ≤ 55 then the watts generated are just the maximum wattage possible. The application assumes that the turbine shuts down and generates zero watts with wind speeds over 55 miles per hour.
Valid nameplate capacities from the generator range from 300 to 8,000,000 watts, inclusive. For watts out of this range, print the following error messages and don’t calculate watts generated.
Nameplate Capacity, g Error message
g < 0 Nameplate capacity must be greater than zero.
0 <= g < 300 Nameplate capacity must be between 300 and 8,000,000 watts.
8,000,000 < g Nameplate capacity must be less than 8,000,000 watts.
For invalid wind speeds, don’t calculate watts generated by the wind turbine. Instead, print one of the following error messages.
Wind speed, s Error message
s < 0 Wind speed must be greater than zero.
0 <= s < 6 Wind speed is not sufficient to power the generator.
55 < s Wind speeds too high. The turbine is not operating.
This program prints a welcome message then prompts the user for the nameplate capacity. If the user enters 0 for the capacity, the program ends. Otherwise the program checks the validity of the nameplate capacity and either prints an error message or prompts the user for the wind speed. Then the program checks the validity of the wind speed and either prints an error message or calculates and prints . watts generated with exactly one digit to the right of the decimal. If the watts generated are less than 1,000, print out “watts”. Example:
The wind turbine generated 650.9 watts today.
If the watts generated is in the range [1,000, …, 1,000,000), print out “kilowatts”. Example:
The wind turbine generated 2.1 kilowatts today.
If the watts generated is greater than or equal to 1,000,000, print out “megawatts”. Example:
The wind turbine generated 4.3 megawatts today.
The program prints a good-bye message upon completion.
Thank you for using the Wind Turbine Calculator.
You must write and use the following functions:
bool getNameplateCapacity( double& n ): prompts the user for nameplate capacity and puts this value in the pass-by-reference variable. Returns true if the nameplate capacity is not zero (true if the user doesn’t want to exit the program), false otherwise.
bool checkNameplateCapacity( double n ): returns true if n is in the valid range of 300, …, 8,000,000 inclusive. Prints out error message if n is out of range as described above.
bool getAndCheckWindSpeed( double& w ): prompts the user for wind speed and puts this value in the pass-by-reference parameter. Checks this input and prints error message if out of range as described above. Returns false if entered speed is out of range, otherwise returns true.
double calcWattsGenerated( double nameplateCapacity, double windSpeed ): returns calculated watts generated (not kilowatts and not megawatts, but watts)
void printWattsGenerated( double watts ): prints out watts or kilowatts or megawatts generated
Use constants as appropriate.
here is what i have so far, making sure i'm on the right course
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
using namespace std;
int main()
{
double nameplateCapacity; // max can be generated per day by windmill
double windSpeed; // average wind speed in mph per day
bool goodInput; // maxWatts or average windspeed error
double watts; // watts generated in one particular day
// set precision for all output
cout.setf( ios::showpoint | ios::fixed );
cout.precision( 1 );
// say hello and get maxWatts for the first time
cout << "Welcome to the Wind Turbine Calculator.\n";
while ( getNameplateCapacity( nameplateCapacity ) )
{
goodInput = checkNameplateCapacity( nameplateCapacity );
// if good maxWatts
if ( goodInput )
{
goodInput = getAndCheckWindSpeed( windSpeed );
// if no error in maxWatts and windSpeed then
// calculate and print watts generated
if( goodInput )
{
watts = calcWattsGenerated( nameplateCapacity, windSpeed );
printWattsGenerated( watts );
} // end if no input error in maxWatts and windSpeed
}// end if good maxWatts
} // end while maxWatts < 0
cout << "Thank you for using the Wind Turbine Calculator.\n";
return( 0 );
}
|