#include<iostream>
#include<windows.h>
#include<string.h>
#include<stdio.h>
usingnamespace std;
int main()
{
char A[20];
cout<<"Enter your password \n";
gets(A);
if(strcmp(A,"Thanosbuster")==0)
{ cout<<"Welcome Mr Stark"<<"\n";
cout<<"How are you Mr Stark?"<<"\n";
char B;
cin >> B;
char fine;
cin >> fine;
if ( fine)
cout<<"I am glad you are in good emotional state sir.\n";
else
cout<<"Sorry to hear that sir.\n";
cout<<"Are going to armour up today sir?\n";
char C;
cin >> C;
char Yes;
cin >> Yes;
if(Yes)
cout<<"I recommend a complete port charge of your arc reactor"<<" if you are going out today i shall cancel the training meeting.\n";
else
cout<<"I hope you have your training meeting with SHEILD today in mind sir if not, this is a reminder.\n";
cout<<"Wnat type of cloth style do you want to wear?Formal or Casual?\n";
char D;
cin >> D;
char Formal;
cin >> Formal;
if(Formal)
cout<<"Oh so you want to be in buisness mode,as you wish sir.";
else
cout<<"Oh so you want to wear casuals ,good choise sir.";
cout<<"Have a good day sir."; }
else
cout<<"Intruder alert shutting down";
return 0;
}
You should add more information about what isn't working.
//Why Not Use Strings Instead For:
Line 10 - gets()
line 11 - strcmp
line 15/17 - Inputting twice?
line 18 - this if statement will almost ALWAYS be true. You want to check if fine == 'f', or better yet, use a string for your input so you can check fine == "fine" .
line 28 - this if statement will also almost always be triggered, you need to check what your variables equal. Yes == 'y' , or again use a string so you can check Yes == "yes".
line 38 - same issue as your other if statements, will always be triggered.
When I use compiler it says it has no mistakes but when I run the program it has a problem with the conditional statement part. I tried to fix it but it was not getting fixed. I think the problem is with the way I wrote the conditions part. Pls tell me your opinions guys i am still very confused about what's going on in this program. I would be very thankful if you helped me.
As zapshe pointed out, there is a large problem with how you have structured your if statements. But to add just a bit more detail, what you're currently doing is simply checking if they have a value that is not zero. A better if statement would be if (fine == "fine")
It seems that you are having troubles with nested conditional branches. I suggest to look at nested conditional branches in depth if you want do some cool stuff.
#include <iostream>
#include <string>
int main() {
/* In C++, it is always better to use a string rather than a char array. */
std::string password;
std::cout << "Enter in a password: ";
std::getline(std::cin, password);
char choice;
if(password == "Thanosbuster") {
std::cout << "How are you doing today?\n >>> ";
std::string mood;
std::getline(std::cin, mood);
if(mood == "fine") {
// do stuff
}
elseif(mood == "not fine") {
// do stuff
}
else {
// do stuff
}
std::cout << "Suiting up? <y/n>: ";
std::cin >> choice; std::cin.ignore();
if(choice == 'y' || choice == 'Y') {
/* Mr. Stark is suiting up today, so do something appropriate here.
* Recommend him something or do whatever. */
}
else {
/* Mr. Stark is not suiting up today and nothing is to be done today. I'm
* too lazy to do checks for no or other input, but you get the point. */
}
}
else {
std::cout << "Intruder alert!\n";
}
return 0;
}