I'm having trouble with this while loop, I want it to keep reprompting the user if they put a number less than 300 and more than 8,000,000. However it keeps giving me "Nameplate capacity must be between 300 and 8,000,000 watts." and keeps saying it for an indefinite time only for me to press ctrl + c to get out of it. (Bare in mind that this is not the whole code but it only excutes this much anyways at the moment.)
#include<iostream>
#include<stdlib.h>
usingnamespace std;
int main()
{
double g; //generator's nameplates
double s; //average wind speed
double w; //watts
int i=0; // repeat
//Intro message
cout << "Greetings, we will be calculation watts per mile per hour\n";
//Collecting info
cout << "Insert Generator's name capacity in watts\n";
cin >> g;
while (i==0)
{
if (g < 300)
{
cout << "Nameplate capacity must be between 300 and 8,000,000 watts.\n";
}
elseif (g > 8,000,000)
{
cout << "Nameplate capacity must be less than 8,000,000.\n";
}
if ((g >= 300)&&(g <= 8,000,000))
{
break;
}
exit (-99);
}
#include<iostream>
#include<stdlib.h>
usingnamespace std;
int main()
{
double g; //generator's nameplates
double s; //average wind speed
double w; //watts
//Intro message
cout << "Greetings, we will be calculation watts per mile per hour\n";
//Collecting info
cout << "Insert Generator's name capacity in watts\n";
/**** Select your preferred code:
cin >> g;
while ( g < 300 || g > 8000000 ) {
cout << "Nameplate capacity must be between 300 and 8,000,000 watts\n";
cin >> g;
}
/////////// OR ////////////////
while ( true ) {
cin >> g;
if ( g < 300 || g > 8000000 ) {
cout << "Nameplate cap. must be beetween ... \n";
else if ( g > 8,000,000 ) { // this doesn't make sense this will just run again ?
cout << "Nameplate cap must be less than 8000000\n";
else
break;
}
***/
exit(-99); // I don't know what is the purpose of this
cout << "Insert today's average daily wind speed\n";
cin >> s;
if (s < 0)
{
cout << "Wind speed must be greater than zero.\n";
}
elseif ((s >= 0) && (s < 6))
{
cout << "Wind speed is not sufficient to power the generator.\n";
}
elseif ((s >= 39) && (s <= 73))
{
cout << "Tropical storm wind speeds. Wind turbine not operating.\n";
}
elseif (s > 73)
{
cout << "TIme to buy a new wind turbine.\n";
}
return 0;
}