Thread: will the header file affect the program?

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    will the header file affect the program?

    i have a testing program with the following code:

    Code:
    #include "stdafx.h"
    #include <iostream.h>
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int choice,ended = 0;
    	while(ended!=2)
    	{
    		cout <<"enter your choice";
    		cin >> choice;
    		if (choice==1)
    		{
    			cout << "hello\n";
    		}
    		else
    		{
    			cout << "bye\n";
    			ended = 2;
    		}
    	}
    	return 0;
    }
    this program works well but when i tried to do the same in a different program, it wont work. once i input 1, the program ended.

    i have include several header files in the second porgram and they are:
    Code:
    #include "stdafx.h"
    #include <fstream.h>
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    the second program perform some file read write tasks and running some *.bat file

    i wonder the header file will affect the result of the program.please help.
    i am using studio.net.....

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Its supposed to end... Thats what you tell it to do. If you want it to wait, check the FAQ.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    ??when i input 1, the program will loop right?

    i have test the first program, when i input noe, the program will loop...

    but i cant do so in teh second program.....

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    by the way.......

    by the way ...i have another question to ask.

    look at the following code:
    Code:
    #include "stdafx.h"
    #include <iostream.h>
    #include <conio.h>
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	cout <<"hello1";
    	char choice;
    	int end=0;
    	while(end!=2)
    	{
    		cout <<"enter your choice";
    		
    		if (choice = getch() =='1')
    		{
    		        cout << "hi";
    		}
    		else
    		{
    			cout << "bye\n";
    			end = 2;
    		}
    	}
    	return 0;
    }
    the problem is when i run the program, the "hello1" will not be printedon the screen.....how to solve the problem?

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    117
    > if (choice = getch() =='1')
    Check the operator precedence table - this does not mean what you want it to


    what do you mean??
    you mean i should set choice = getch(),then if (choice == '1')?

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    It should be:
    >>if ((choice = getch()) =='1')

    (note the extra brackets)

    Doing it your way, the comparison gets resovled first, then its result (1 or 0) is assigned to choice.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM