trying If Statements but got 8 errors dont understand some of em


I was trying if statements and else and I had a few errors. I was doing the example because I feel like that best way to learn for me. I going to show you my errors that pop-up and I would appreciate any feedbacks.


I checked all the syntax and I think all of them are there. I made sure with the brackets.

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

#include <iostream>

using namespace std;

int main ()
{
   int age;

   cout<<"Please enter your Age";
   cin >>age;
   cin.ignore ();

   if ( age< 100)(
  cout<<"You are pretty young!\n";
  )
  else (age ==100)(
     cout<<"You are really old\n";
)
cin.get();
}




||=== if statments, Debug ===|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|1|error: iostream: No such file or directory|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|3|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c||In function 'main':|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|9|error: 'cout' undeclared (first use in this function)|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|9|error: (Each undeclared identifier is reported only once|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|9|error: for each function it appears in.)|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|10|error: 'cin' undeclared (first use in this function)|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|14|error: expected ')' before ';' token|
C:\Users\gameffect\Documents\if statments\ifstatementsex.c|16|error: expected ';' before 'else'|
||=== Build finished: 8 errors, 0 warnings ===|


Last edited on
1
2
3
4
5
6
if ( age< 100)(
  cout<<"You are pretty young!\n";
  )
  else (age ==100)(
     cout<<"You are really old\n";
)

You're using parentheses for brackets, switch to {}, you're using them for the main function already
Last edited on
It seems that somehow, iostream wasn't included. I myself am not sure how to fix that, but at least you got a free diagnosis.
u were right that solved the problem thanks!
Topic archived. No new replies allowed.