#include <iostream>
usingnamespace std;
int main ()
{
int starting_year;
int population;
int temperature;
int n = 0;
cout << "Please enter starting year. " << endl;
cin >> starting_year;
cout << "Please enter starting population. " << endl;
cin >> population;
while (n <= 9)
{
cout << "What was the lowest winter temperature in " << starting_year << " ?" << endl;
cin >> temperature;
cout << population << endl;
if (temperature < 0)
{
population = population - (population * 0.15);
}
elseif (0 <= temperature <= 25)
{
population = population - (population * 0.1);
}
else
{
population = population + (population * 0.14);
}
}
return 0;
}.
#include <iostream>
// using namespace std; // avoid
int main ()
{
int starting_year;
int population;
// int temperature;
// int n = 0;
std::cout << "Please enter starting year: " ;
std::cin >> starting_year;
std::cout << "Please enter starting population: " ;
std::cin >> population;
// while (n <= 9) // this is an infinite loop; the value of 'n' is never changed
for( int n = 0 ; n < 10 ; ++n ) // canonical classical for loop
{
// cout << "What was the lowest winter temperature in " << starting_year << " ?" << endl;
std::cout << "\nWhat was the lowest winter temperature in " << starting_year + n << "? " ;
int temperature ;
std::cin >> temperature;
// cout << population << endl;
if (temperature < 0)
{
population = population - (population * 0.15);
}
//else if (0 <= temperature <= 25) // this won't do what you think it does
// need to write it as if ( 0 <= temperature && temperature <= 25 )
// or simpler:
elseif ( temperature <= 25) // we have already checked if temperature is less than zero
{
population = population - (population * 0.1);
}
else
{
population = population + (population * 0.14);
}
std::cout << "population at the end of year " << starting_year + n << " is " << population << '\n' ;
}
// return 0; // this is implicit
// }. // **** remove the period after }
}