need help with conditional statements

im kinda new with these
to cut to the chase basically im making a game, interactive fiction to be exact.

for example:

1
2
3
4
5
6
  char choice[5];

  if (choice == "START")
     {
      cout<<"blah blah blah";
     }


but i can't seem to make it work
it's showing nothing

but this works

1
2
3
4
5
6
  char choice;
  
  if (choice == 'Y')
     {
     cout<<"blah blah blah";
     }


i don't get it

and can i ask how to sort of delay the outputs?

for example:

*knock* (1 sec. delay)
*knock* (1 sec. delay)
*knock* (1 sec. delay)
*knock* (1 sec. delay)
Last edited on
Neither C nor C++ supports comparison of two character arrays. If you're going to use C style strings, you have to use the strcmp library function.

Change choice to type std::string and your comparison will work as coded.
i don't know what strcmp but im studying it now thanks

can you help about my second problem too?

output should be like this:

*knock*
(1 second delay)
*knock*
(1 second delay)
*knock*
C/C++ doesn't have any built-in function to delay. That's operating system specific.

If you're on Windows, look at Sleep().
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
#include <thread>
#include <chrono>

int main()
{
    std::string choice ; // http://www.cprogramming.com/tutorial/string.html
    std::cin >> choice ;
    if( choice == "START" ) std::cout << "blah blah blah\n" ;

    const int num_knocks = 4 ;
    for( int i = 0 ; i < num_knocks ; ++i )
    {
        std::cout << "*knock* " << std::flush ;

        // http://en.cppreference.com/w/cpp/thread/sleep_for
        std::this_thread::sleep_for( std::chrono::seconds(1) ) ; // 1 second delay
    }
    std::cout << '\n' ;
}
Topic archived. No new replies allowed.