please help me to compile this

I dont know why this wont compile.. please help

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 ()
{
	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);
		}
		else if (0 <= temperature <= 25)
		{
			population = population - (population * 0.1);
		}
		else
		{
			population = population + (population * 0.14);
		}
	
	}
	
	
	return 0;
}.
Last edited on
> I dont know why this wont compile.. please help

You have a period after the closing brace on line 44.

Tip: if the compiler emits a poorly worded diagnostic, note the line number in the error diagnostic, and look carefully at that line.

LLVM (fair):
main.cpp:3:2: error: cannot use dot operator on a type
}.
 ^ 

GNU (poor):
main.cpp:3:2: error: expected unqualified-id before '.' token
 }.
  ^

http://coliru.stacked-crooked.com/a/fec17a5578745b2e

Microsoft (good):
cpp(3): syntax error: '.'

http://rextester.com/BHEJ20794

There are logical errors in your code.

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
45
46
47
48
49
50
#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:
		else if ( 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 }
}
Topic archived. No new replies allowed.