Please help!!

What is wrong in this code?


#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
cout<<"Introdu un numar,mai putin 5";
cin>>a;
{
if (a!=5)
cout<<"Introdu un numar,mai putin 5";
cin>>b;
}
else
cout<<"Bai raule!Ti-am zis sa nu pui 5!";
{
if (b!=5)
cout<<"Introdu orice numar,mai putin 5";
cin>>c;
}
else
cout<<"Bai raule!Ti-am spus sa nu pui 5!";
{
if (c!=5)
cout<<"Esti tare!N ai pus 5 deloc!";
}
else
cout<<"Bai de ce ai pus 5??";
return 0;
}
Last edited on
You want to do it 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
30
31
32
33
34
35
36
37
#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
cout<<"Introdu un numar,mai putin 5";
cin>>a;

if (a!=5)
{
cout<<"Introdu un numar,mai putin 5";
cin>>b;
}
else
{
cout<<"Bai raule!Ti-am zis sa nu pui 5!";
}

if (b!=5)
{
cout<<"Introdu orice numar,mai putin 5";
cin>>c;
}
else
{
cout<<"Bai raule!Ti-am spus sa nu pui 5!";
}
if (c!=5)
{
cout<<"Esti tare!N ai pus 5 deloc!";
}
else
{
cout<<"Bai de ce ai pus 5??";
}
return 0;
}


Move the open curly brace to after line 9.
{
if (a!=5)
cout<<"Introdu un numar,mai putin 5";
cin>>b;


Basically it is a good thing to use curly brackets whenever you use
if() and else if and else


Last edited on
Topic archived. No new replies allowed.