I am running into a issue with the loops. I need the program to give the user two chances to enter the correct variables. If they fail the second time it closes the program. However, it also closes the program if they input the correct variables without doing the for loop. The for statement is supposed to utilize the equation and give 25 years worth of data 0-25years. How do I make the loop not kick me out so the for statement will start?
#include <iomanip>
#include <iostream>
usingnamespace std;
int main(void)
{
double CurrentYr, NextYr, Rate;
cout << "Enter the initial egret population: \n";
cin >> CurrentYr;
cout << "Enter the Rate: \n";
cin >> Rate;
while ((CurrentYr>=0&&CurrentYr<=1000000)&(Rate<=4&&Rate>=0)) // if the input is correct
{
cout << "Enter the initial egret population: \n";
cin >> CurrentYr;
cout << "Enter the Rate: \n";
cin >> Rate;
cout << "\n Year Population\n";
cout << "---- ----------\n";
NextYr=Rate*CurrentYr*(1-(CurrentYr)/1000000)
for(NextYr=0; NextYr=<25; NextYr++)
{
cout << setw(4) << right <<"";
}
if ((CurrentYr<0||CurrentYr>1000000)||(Rate>4||Rate<0)) // first trail
{
cout << "Enter a valid input range greater than 0 and less than 1000000 for population: \n";
cout << "Enter a valid input range greater than 0 and less than 4 for rate \n";
cout << "Enter the initial egret population: \n";
cin >> CurrentYr;
cout << "Enter the Rate: \n";
cin >> Rate;
if ((CurrentYr<0||CurrentYr>1000000)||(Rate>4||Rate<0))
{
cout << "The program will now close next time enter in the correct variables. \n";// last attempt
}
}
}
cout << endl;
cin.ignore();
return 0;
}
#include <iomanip>
#include <iostream>
usingnamespace std;
int main(void)
{
double CurrentYr, NextYr, year; //making the variables
float Rate;
year=0;
cout << "Enter the initial egret population: \n";
cin >> CurrentYr;
cout << "Enter the Rate: \n";
cin >> Rate;
if((CurrentYr<=0&&CurrentYr>=1000000)&&(Rate>4&&Rate<=0)) // first trail
{
cout << "Enter a valid input range greater than 0 and less than 1000000 for population: \n";
cout << "Enter a valid input range greater than 0 and less than 4 for rate \n";
cout << "Enter the initial egret population: \n";
cin >> CurrentYr;
cout << "Enter the Rate: \n";
cin >> Rate;
if((CurrentYr<0||CurrentYr>1000000)||(Rate>4&&Rate<0))
{
cout << "The program will now close next time enter in the correct variables. \n";// last attempt
}
}
else
{
cout << "\n Year Population\n"; // this is making the record over 25 years
cout << " ---- ----------\n";
for(year=0; year<=25; year++)
{
NextYr=Rate*CurrentYr*(1-(CurrentYr)/1000000);
cout << setw(4) << year << setw(15) << CurrentYr<< endl;
CurrentYr = NextYr;
}
}
cout << endl;
cin.ignore();
return 0;
}
if((CurrentYr<=0&&CurrentYr>=1000000)&&(Rate>4&&Rate<=0)) // first trail
{
cout << "Enter a valid input range greater than 0 and less than 1000000 for population: \n";
cout << "Enter a valid input range greater than 0 and less than 4 for rate \n";
cout << "Enter the initial egret population: \n";
cin >> CurrentYr;
cout << "Enter the Rate: \n";
cin >> Rate;
elseif((CurrentYr<0||CurrentYr>1000000)||(Rate>4&&Rate<0))
{
cout << "The program will now close next time enter in the correct variables. \n";// last attempt
}
the latest code i posted worked I was just giving it so people could see what I changed, the main code which I could never get to work was the original with the two if statements