guys i really need help i am not able make my code work

not working i used DEV C++ pls help with this code this is a SOS call pls help

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
39
40
41
42
43
44
45
46
47
48
   #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"<<"\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;
}
Last edited on
This is a huge code for me guys pls help me out pls
i need urgent assistance this is no homework or nothing i made this code for fun pls help
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.
We're not psychic. Tell us what it does that you don't like, or what it doesn't do that you wish it did.

Stop using char arrays
Stop using string.h
Stop using stdio.h
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.
I told you the issues with your if statements. The variable name means nothing, it's what the variable holds that matters.

if(yes) and if(fine) DON'T check if the input was "yes" or "fine".
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")

You might want to check out the tutorials here! They're quite useful. http://www.cplusplus.com/doc/tutorial/


P.S. This isn't anything big, but you should really label the post as a question, not as news.
Last edited on
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.

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>
#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
    }
    else if(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;
}
Topic archived. No new replies allowed.