Delay

This is a discussion on Delay within the C++ Programming forums, part of the General Programming Boards category; I'm trying to put a delay in this text game im making delay(1000); but it dont work need an identifier ...

  1. #1
    Unregistered
    Guest

    Post Delay

    I'm trying to put a delay in this text game im making delay(1000);
    but it dont work need an identifier and i cant find it... if you can plz email me at nogork@yahoo.com or icq me at 97034780.

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Include windows.h and use Sleep() instead.
    And there must be a big S when using it.

  3. #3
    Unregistered
    Guest

    ok

    nothing inside the ()?? ok thx

  4. #4
    Unregistered
    Guest

    heres my code

    its just a dumb text game but can you tell me whats wrong (aint very far yet).

    #include <iostream.h>
    #include <windows.h>

    void main(){
    int number = 1;

    cout << "You open your eyes to see a lady bent over you appling medication to your wound on your leg.\n";
    cout << "You can ask:\n1 = Will I be alright?\n2 = Can I leave now?\n3 = What happened?\n";
    cin >> number;
    if (number == 1)
    cout << "Will I be alright?\n\n";
    if (number == 1)
    cout << "Yes, you just need some rest.\n\n";
    if (number == 2)
    cout << "Can I leave now?\n\n";
    if (number == 2)
    cout << "You can, but it won't do you any good. The stiches will break.\n\n";
    if (number == 3)
    cout << "What happened?\n\n";
    if (number == 3)
    cout << "You were fighting some nasty orc's outside of town. They knocked you out and were going to eat you, but papa found you. I will take care of you until you can go back out on your own.\n";
    cout << "You feel yourself drift off to sleep.\n\n";
    Sleep(1000);
    cout << "\n\nZzZzZzZz......\n";
    Sleep(1000);
    cout << "\n\nZzZzZzZzZzZzZzZz..\n";
    cout << "\n\nBOOOOOOOOM!!!!\n";
    cout << "You sit up quickly looking around. You spot your pants and scabbard on the chair next to your bed, and quickly get up and put them on.\nYou slip on your boots and run down the spiral staircase to see what the noise was.\nWhen you get out you look to the left and see a squad of orcs carrying your friends away.\nYou try to chase after them, but can't keep up.\nYou hear noises behind you.\n\nShould you:\n1 = Turn around towards the noise.\n2 = Keep trying to keep up with the orc's taking your friends.\n3 = Run away into a deep dark cave.\n";
    cin >> number;
    if (number == 1)
    cout << "You turn around like lightning and draw your sword. A orc swings his mighty club at you but you dodge it. You jab but he was too quick, He swings it again but you move and stab him in the ribs.\n";

    }

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    23

    Re: heres my code

    Originally posted by Unregistered
    its just a dumb text game but can you tell me whats wrong (aint very far yet).

    #include <iostream.h>
    #include <windows.h>

    void main(){
    int number = 1;

    cout << "You open your eyes to see a lady bent over you appling medication to your wound on your leg.\n";
    cout << "You can ask:\n1 = Will I be alright?\n2 = Can I leave now?\n3 = What happened?\n";
    cin >> number;
    if (number == 1)
    cout << "Will I be alright?\n\n";
    if (number == 1)
    cout << "Yes, you just need some rest.\n\n";
    if (number == 2)
    cout << "Can I leave now?\n\n";
    if (number == 2)
    cout << "You can, but it won't do you any good. The stiches will break.\n\n";
    if (number == 3)
    cout << "What happened?\n\n";
    if (number == 3)
    cout << "You were fighting some nasty orc's outside of town. They knocked you out and were going to eat you, but papa found you. I will take care of you until you can go back out on your own.\n";
    cout << "You feel yourself drift off to sleep.\n\n";
    Sleep(1000);
    cout << "\n\nZzZzZzZz......\n";
    Sleep(1000);
    cout << "\n\nZzZzZzZzZzZzZzZz..\n";
    cout << "\n\nBOOOOOOOOM!!!!\n";
    cout << "You sit up quickly looking around. You spot your pants and scabbard on the chair next to your bed, and quickly get up and put them on.\nYou slip on your boots and run down the spiral staircase to see what the noise was.\nWhen you get out you look to the left and see a squad of orcs carrying your friends away.\nYou try to chase after them, but can't keep up.\nYou hear noises behind you.\n\nShould you:\n1 = Turn around towards the noise.\n2 = Keep trying to keep up with the orc's taking your friends.\n3 = Run away into a deep dark cave.\n";
    cin >> number;
    if (number == 1)
    cout << "You turn around like lightning and draw your sword. A orc swings his mighty club at you but you dodge it. You jab but he was too quick, He swings it again but you move and stab him in the ribs.\n";

    }
    Yah its correct but, your coding style is pretty bad. Why do you have so many if statements for the SAME condition?

    Try looking up switch/case statements since it will help simplify your code. Good luck.

    oh yeah ...if the reason why you are using so many if statements try this,

    Code:
    if (number == 1) {
      cout << "Will I be alright?\n\n"; 
      cout << "Yes, you just need some rest.\n\n"; 
    }

  6. #6
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Code:
    #include <iostream.h> 
    #include <windows.h> 
    
    int main(void) { 
    int number = 1; 
    
    cout << "You open your eyes to see a lady bent over you appling medication to your wound on your leg.\n"; 
    cout << "You can ask:\n1 = Will I be alright?\n2 = Can I leave now?\n3 = What happened?\n"; 
    cin >> number; 
    switch(number) {
    case 1:
    cout << "Will I be alright?\n\n"; 
    Sleep(1000);
    cout << "Yes, you just need some rest.\n\n"; 
    break;
    case 2:
    cout << "Can I leave now?\n\n"; 
    Sleep(1000);
    cout << "You can, but it won't do you any good. The stiches will break.\n\n";
    break;
    case 3: 
    cout << "What happened?\n\n"; 
    Sleep(1000);
    cout << "You were fighting some nasty orc's outside of town.\nThey knocked you out and were going to eat you, \nbut papa found you. \nI will take care of you until you can go back out on your own.\n\n";
    Sleep(2500); 
    cout << "You feel yourself drift off to sleep.\n\n"; 
    Sleep(1000); 
    cout << "\n\nZzZzZzZz......\n"; 
    Sleep(1000); 
    cout << "\n\nZzZzZzZzZzZzZzZz..\n"; 
    Sleep(500);
    cout << "\n\nBOOOOOOOOM!!!!\n"; 
    Sleep(500);
    cout << "You sit up quickly looking around. You spot your pants and scabbard on the chair next to your bed, and quickly get up and put them on.\nYou slip on your boots and run down the spiral staircase to see what the noise was.\nWhen you get out you look to the left and see a squad of orcs carrying your friends away.\nYou try to chase after them, but can't keep up.\nYou hear noises behind you.\n\nShould you:\n1 = Turn around towards the noise.\n2 = Keep trying to keep up with the orc's taking your friends.\n3 = Run away into a deep dark cave.\n"; 
    cin >> number; 
    if (number == 1) {
    cout << "You turn around like lightning and draw your sword. A orc swings his mighty club at you but you dodge it. You jab but he was too quick, He swings it again but you move and stab him in the ribs.\n"; 
    }
    
    }

    EDIT:: void main() is evil!
    Last edited by ErionD; 03-30-2002 at 12:48 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Regarding delay in the connection
    By byatin in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-19-2008, 02:59 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  4. 2-3 Second delay with alarm()
    By Longie in forum C Programming
    Replies: 11
    Last Post: 06-20-2004, 08:46 PM
  5. Delay
    By CanadianOutlaw in forum C++ Programming
    Replies: 4
    Last Post: 09-13-2001, 06:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21