\Program4.cpp:65:2: error: expected unqualified-id before 'if'

Write your question here.

Hi,

I'm trying to build this this example code in Eclipse but I get the error:
\Program4.cpp:65:2: error: expected unqualified-id before 'if'

Line 65 is the line with the commentt: if(seedColor == "blue")

Would be nice if you could help me

Kind regards,
Marco

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
#include <iostream>
#include <string>

using namespace std;

int main()
{
	// Get seed color
	string seedColor = "";
	cout << "Enter the seed color (red or blue): \n";
	cin >> seedColor;

	// Get temp
	int temp = 0;
	cout << "Enter the temperature (F): \n";
	cin >> temp;

	// Get the soil moisture
	string soilMoisture = "";
	cout << "Enter the soil moisture (wet or dry): \n";
	cin >> soilMoisture;

	// If red seed
	if(seedColor == "red")
	{
		// If temp >= 75
		if(temp >= 75)
		{
			// If the soil is wet
			if(soilMoisture == "wet")
			{
				// Output sunflower
				cout << "A sunflower will grow.\n";
			}
			// If the soil is dry
			if(soilMoisture == "dry")
			{
				// Output dandelion
				cout << "A dandelion will grow.\n";
			}
		}
	}
		// Otherwise
		else
		{
			// Output mushroom
			cout << "A mushroom will grow.\n";
		}
	}
	// If blue seed
	if(seedColor == "blue")
	{
		// If temp is between 60 and 70
		if(temp >= 60 && temp <= 70)
		{
			// If the soil is wet
			if(soilMoisture == "wet")
			{
				// Output dandelion
				cout << "A dandelion will grow.\n";
			}

			// If the soil is dry
			if(soilMoisture == "dry")
			{
				// Output sunflower
				cout << "A sunflower will grow.\n";
		}
			// Otherwise
			else
			{
				 // Output mushroom
				 cout << "A mushroom will grow.\n";
			}
	}
}
Last edited on
closed account (E0p9LyTq)
Apparently you had a few misplaced parentheses.

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>

int main()
{
   // Get seed color
   std::string seedColor = "";
   std::cout << "Enter the seed color (red or blue): \n";
   std::cin >> seedColor;

   // Get temp
   int temp = 0;
   std::cout << "Enter the temperature (F): \n";
   std::cin >> temp;

   // Get the soil moisture
   std::string soilMoisture = "";
   std::cout << "Enter the soil moisture (wet or dry): \n";
   std::cin >> soilMoisture;

   // If red seed
   if (seedColor == "red")
   {
      // If temp >= 75
      if (temp >= 75)
      {
         // If the soil is wet
         if (soilMoisture == "wet")
         {
            // Output sunflower
            std::cout << "A sunflower will grow.\n";
         }
         // If the soil is dry
         if (soilMoisture == "dry")
         {
            // Output dandelion
            std::cout << "A dandelion will grow.\n";
         }
      }
      // Otherwise
      else
      {
         // Output mushroom
         std::cout << "A mushroom will grow.\n";
      }
   }

   // If blue seed
   if (seedColor == "blue")
   {
      // If temp is between 60 and 70
      if (temp >= 60 && temp <= 70)
      {
         // If the soil is wet
         if (soilMoisture == "wet")
         {
            // Output dandelion
            std::cout << "A dandelion will grow.\n";
         }

         // If the soil is dry
         if (soilMoisture == "dry")
         {
            // Output sunflower
            std::cout << "A sunflower will grow.\n";
         }
      }
      // Otherwise
      else
      {
         // Output mushroom
         std::cout << "A mushroom will grow.\n";
      }
   }
}
This is cool, thank you for the quick answer.
I thought it was something like that.

Yesterday I read an article about do not use "using namespace std", nice to see how to use that in this code.

Kind regards,


Topic archived. No new replies allowed.