for loop problem

This is a discussion on for loop problem within the C++ Programming forums, part of the General Programming Boards category; Hello I have a question. Why is it that this 2 for statements combines each time I execute it. Instead ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    14

    Unhappy for loop problem

    Hello I have a question. Why is it that this 2 for statements combines each time I execute it.
    Instead of writing 10 "." each, it writes 20 "." instead. Can you guys help me?

    I want to execute the program like this:
    Enter IP Address:
    Enter Port Number:

    ..........<--delay()
    Connected to remote host "<<ip<<" at "<<"port "<<port
    Exiting
    ..........<--delay()

    I need the experts help please. Thank you very much!

    Code:
    void timer();
    void connect();
    
    char ip[15];
    int port;
    main ()
    {
    cout<<"Enter IP Address: ";
    cin>>ip;	
    cout<<"Enter Port Number: ";
    cin>>port;
    connect();
    timer();
    
    return 0;
    }
    void connect()	
    {	
    	cout<<"\nConnected to remote host "<<ip<<" at "<<"port "<<port;
            cout<<"\nExiting";
            for (int a=0;a<10;a++)
            { 
                      printf(".");
                      Sleep(500);
            }	
    }
    void timer()
    {
        int i;
    	for( i=0;i<10;i++)
    	{
    		printf(".");
    		Sleep(500);
    	}
    }
    Last edited by Makoy; 12-25-2004 at 09:00 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,451
    because the for loop in connect() is after you print the "connected to host" message?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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