/* File name: xxxxxxx
* Author: xxxxx
* Date: 9/23/2013
* Description: This program will calculate how many watts are generated per day by a single wind turbine and convert it into it's appropriate conversion.
*/
#include<iostream>
#include<stdlib.h>
#include<stdio.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
while (i==0)
{
cout << "Insert Generator's name capacity in watts (type -99 to exit)\n";
cin >> g;
if (g < 300 && g != -99)
{
cout << "Nameplate capacity must be between 300 and 8,000,000 watts.\n";
}
elseif (g > 8000000)
{
cout << "Nameplate capacity must be less than 8,000,000.\n";
}
elseif (g >= 300 && g <= 8000000)
{
break;
}
if(g=-99)
{
cout << "Thanks for using this program!\n";
exit(0);
}
}
while (i==0)
{
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";
exit(0);
}
elseif ((s >= 39) && (s <= 73))
{
cout << "Tropical storm wind speeds. Wind turbine not operating.\n";
exit(0);
}
elseif (s > 73)
{
cout << "Time to buy a new wind turbine.\n";
exit(0);
}
elseif (s >= 6 && s <= 38)
{
break;
}
}
w = g*(s/28)*(s/28)*(s/28);
if(w < 1000)
{
printf("Your windmill generated %.1f watts today!\n", w);
}
elseif((w > 1000) && (w < 1000000))
{
w = w/1000;
printf("Your windmill generated %.1f kilowatts today!\n", w);
}
elseif(w > 1000000)
{
w = w/1000000;
printf("Your windmill generated %.1f megawatts today!\n", w);
}
}
No, I want it to only loop with (g<300) and (g>8 million) excluding -99 which I want to use to terminate the whole program.
Like.
welcome, enter a number for nameplate
6
must be between 300-8 mil.
Enter a number for nameplate.
8.1mil
its over 8 mil
Enter a number for nameplate.
-99
Thanks for using this program.
while (i==0)
{
cout << "Insert Generator's name capacity in watts (type -99 to exit)\n";
cin >> g;
if (g < 300 && g != -99)
{
cout << "Nameplate capacity must be between 300 and 8,000,000 watts.\n";
}
if (g > 8000000)
{
cout << "Nameplate capacity must be less than 8,000,000.\n";
}
if (g >= 300 && g <= 8000000)
{
break;
}
if(g==-99)
{
cout << "Thanks for using this program!\n";
exit(0);
}
}
You have a while loop for a reason why not use it?
while( g > 299 && g < 8e6 && g != -99 )
or even while( g != -99 )[/code] but i would suggest method one.
Your i == 0 loops are basically the same as while( true ) , while( 1 ) , while( anything ) because all you did was declare int i = 0 then it appears you are doing nothing with it.