What's wrong with my if statements?

Mar 1, 2013 at 5:04am
Hello, I'm writing this simple program using continuous if statements. Although it seems to me that I've written everything correctly, when I compile it, there are several errors. I'm a beginner and I don't quite understand yet how to spot and fix my errors. Some insight would be greatly appreciated.

// This program calculates boiling point and freezing point
#include <iostream>
using namespace std;
  
int main () {
  
  int temperature, alcohol, mercury, oxygen, water;
  
  cin >> temperature;
  if (temperature <= -173)
     cout << "alcohol freezes\n";
  if (temperature >= 172)
     cout << "alcohol boils\n";
  if (temperature <= -38)
     cout << "mercury freezes\n";
  if (temperature >= 676)
     cout << "mercury boils\n";
  if (temperature <= -362)
     cout << "oxygen freezes\n";
  If (temperature >= 306) 
     cout << "oxygen boils\n";   
  If (temperature <= 32) 
     cout << "water freezes\n";
  If (temeprature >= 212)
     cout <<  "water boils\n";  
 return 0;
  
}
Mar 1, 2013 at 5:13am
What are the errors? Please tell us what the compiler is saying is wrong.

Also, use [code] tags around your code instead of output ones.
Last edited on Mar 1, 2013 at 5:13am
Mar 1, 2013 at 5:16am
The last three ifs are in capital which shouldn't be and the last word of temeprature is wrong you should write it like this temperature.
Mar 1, 2013 at 5:18am
should be like this.
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
#include <iostream>
using namespace std;
  
int main () {
  
  int temperature, alcohol, mercury, oxygen, water;
  
  cin >> temperature;
  if (temperature <= -173)
     cout << "alcohol freezes\n";
  if (temperature >= 172)
     cout << "alcohol boils\n";
  if (temperature <= -38)
     cout << "mercury freezes\n";
  if (temperature >= 676)
     cout << "mercury boils\n";
  if (temperature <= -362)
     cout << "oxygen freezes\n";
  if (temperature >= 306) 
     cout << "oxygen boils\n";   
  if (temperature <= 32) 
     cout << "water freezes\n";
  if (temperature >= 212)
     cout <<  "water boils\n";  

  system ("pause");
 return 0;
  
}
Mar 1, 2013 at 5:19am
I see thanks for the input!

Now I still have one more error in which my compiler says

In function âint main()â:
Mar 1, 2013 at 5:28am
that's not the error. That's telling you where the error is.
Mar 1, 2013 at 5:28am
There is more to it than that. What is the actual error? All you've written is that the compiler says the error is inside main().
Mar 1, 2013 at 5:32am
Sorry my mistake! I've fixed all my errors. I'm still learning how to work C++. thanks so much!
Mar 1, 2013 at 5:35am
it works perfectly with me there is no error. I think it may give you some warnings because you declare some variables and you did not use them.

alcohol, mercury, oxygen, water;
Topic archived. No new replies allowed.