almost done making a mini greeting code pls help.

i have made a conditional password lock statement program. it is as good as log in process and a greeting from the system .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  clude<iostream>
  #include<windows.h>
  #include<string.h>
  #include<stdio.h>
  using namespace std;
  int main()
{   
   char A[20];
   cout<<"Enter your password \n";
   gets(A);
  {{if(strcmp(A,"Thanosbuster")==0)
	cout<<"Welcome Mr Stark";
   cout<<"How are you Mr Stark?";
   char B; cin >> B; char fine; cin>> fine;
   if (B==fine)
   cout<<"I am glad you are in good emotional state.";
   else
   cout<<"Sorry to hear that sir";}
   else
   cout<<"Intruder alert";}
   
}
Last edited on
This is a real SOS question. Pls help. My compiler keeps on saying that there is no previous if statement for the last statement.
Here is your code, indented to match the block structure:
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
#include < iostream >
#include<windows.h>
#include<string.h>
#include<stdio.h>
    using namespace std;
int
main()
{
    char A[20];
    cout << "Enter your password \n";
    gets(A);
    {
	{
	    if (strcmp(A, "Thanosbuster") == 0)
		cout << "Welcome Mr Stark";
	    cout << "How are you Mr Stark?";
	    char B;
	    cin >> B;
	    char fine;
	    cin >> fine;
	    if (B == fine)
		cout << "I am glad you are in good emotional state.";
	    else
		cout << "Sorry to hear that sir";
	}
	else
	cout << "Intruder alert";
    }

}

As you can see, line 15 is the only statement that gets executed when the if on line 14 is true.

The true part of an if must be a single statement or a block enclosed in braces. I suspect you mean 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>
#include<windows.h>
#include<string.h>
#include<stdio.h>
    using namespace std;
int
main()
{
    char A[20];
    cout << "Enter your password \n";
    gets(A);
    {

	if (strcmp(A, "Thanosbuster") == 0) {
	    cout << "Welcome Mr Stark";
	    cout << "How are you Mr Stark?";
	    char B;
	    cin >> B;
	    char fine;
	    cin >> fine;
	    if (B == fine)
		cout << "I am glad you are in good emotional state.";
	    else
		cout << "Sorry to hear that sir";
	}
	else
	    cout << "Intruder alert";
    }
}

just answer okay i have been waiting too long
never mind i got it so dumb nobody even cares to answer for two hours
If you can figure it out yourself, that's the best route. It's always best to find the answer yourself rather then be spoon fed them. Also, people here have lives, they can't be on the forum all hours of the day.
i know but atleast one person could have helped
just answer okay i have been waiting too long
I answered an hour and a half before you posted that.

nobody even cares to answer for two hours
You may misunderstand this site. Everyone here is a volunteer. We answer questions when we have some time and desire. There's no coordinated schedule, so hours can go by when nobody is logged in trying to answer questions. Basically, there's no guarantee when, or even if, your question will get answered.

So I think the words you're looking for are "Thank you." :)
Thanks everyone
Topic archived. No new replies allowed.