Error Message

This is a discussion on Error Message within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I am trying to help my friend, he is using V C++. The problem that we are having ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Error Message

    Hi guys,
    I am trying to help my friend, he is using V C++.
    The problem that we are having is this error message:

    Code:
    #include <iostream.h>
    
    float v1,v2,v3,v4,v5;
    
    void getValues()
    {
    
    	cout<<" Please enter the first Value: " ;
    	cin>> v1;
    
    	cout<<" Please enter the secod Value: " ;
    	cin>> v2;
    
    	cout<<" Please enter the Third Value: " ;
    	cin>> v3;
    
    	cout<<" Please enter the Fourth Value: " ;
    	cin>> v4;
    
    	cout<<" Please enter the Fifth Value: " ;
    	cin>> v5;
    
    }
    
    
    float CalcAvarage (float v01, float v02,  float v03, float v04, float v05)
    {
    
    	float ave;
    
    	float scores[5];
    	scores[0]= v01;
    	scores[1]= v02;
    	scores[2]= v03;
    	scores[3]= v04;
    	scores[4]= v05;
    	
    	float temp;
    	for (int i=0; i<5; i++)
    		for ( int j= i+1; j<5; j++)
    			if( scores[i] <= scores[j]){
    				temp = scores[i]; 
    				scores[i]= scores[j]; 
    				scores[j] = temp;
    			}// end if
    	for ( i=0; i<5; i++){
    		cout<<" Arrange the scores like " << i<< "  is : "<< scores[i];
    	}
    	cout<<endl<<endl;;
    
    	for(  i=0; i<4; i++){
    	 ave += scores[i];  
    	}
    	ave = ave /4;
    	
    return ave;
    }
    
    
    float findLowest ()
    {
    
    	float lowest;
    	
    	lowest= v1;
    	if (lowest <= v2)
    		lowest =  v2;
    	if (lowest <= v3)
    		lowest =  v3;
    	if (lowest <= v4)
    		lowest =  v4;
    	if (lowest <= v5)
    		lowest =  v5;
    
    
    return lowest;
    }
    
    
    
    int main()
    {
    
    	float ave0;
    	float lowest;
    	
    	getValues();
    	lowest = findLowest();
    
    	
    	ave0 = CalcAvarage(v1, v2, v3, v4, v5);
    
    return 0;
    }
    Here is the error message :

    Fatal error C1010: unexpected end of file while looking for precompiled header directive
    Error executing cl.exe.

    update, there is no error message, but the program crash.

    p2.dll - 1 error(s), 0 warning(s)
    Last edited by NANO; 05-09-2003 at 09:58 PM.
    C++
    The best

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Its telling you that it cant find iostream.h, so lets try it without the h and with namespace.

    try this code:

    Code:
    #include <iostream>
    
    using namespace std;
    
    float v1,v2,v3,v4,v5;
    
    void getValues()
    {
    
    	cout<<" Please enter the first Value: " ;
    	cin>> v1;
    
    	cout<<" Please enter the secod Value: " ;
    	cin>> v2;
    
    	cout<<" Please enter the Third Value: " ;
    	cin>> v3;
    
    	cout<<" Please enter the Fourth Value: " ;
    	cin>> v4;
    
    	cout<<" Please enter the Fifth Value: " ;
    	cin>> v5;
    
    }
    
    
    float CalcAvarage (float v01, float v02,  float v03, float v04, float v05)
    {
    
    	float ave;
    
    	float scores[5];
    	scores[0]= v01;
    	scores[1]= v02;
    	scores[2]= v03;
    	scores[3]= v04;
    	scores[4]= v05;
    	
    	float temp;
    	for (int i=0; i<5; i++)
    		for ( int j= i+1; j<5; j++)
    			if( scores[i] <= scores[j]){
    				temp = scores[i]; 
    				scores[i]= scores[j]; 
    				scores[j] = temp;
    			}// end if
    	for ( i=0; i<5; i++){
    		cout<<" Arrange the scores like " << i<< "  is : "<< scores[i];
    	}
    	cout<<endl<<endl;;
    
    	for(  i=0; i<4; i++){
    	 ave += scores[i];  
    	}
    	ave = ave /4;
    	
    return ave;
    }
    
    
    float findLowest ()
    {
    
    	float lowest;
    	
    	lowest= v1;
    	if (lowest <= v2)
    		lowest =  v2;
    	if (lowest <= v3)
    		lowest =  v3;
    	if (lowest <= v4)
    		lowest =  v4;
    	if (lowest <= v5)
    		lowest =  v5;
    
    
    return lowest;
    }
    
    
    
    int main()
    {
    
    	float ave0;
    	float lowest;
    	
    	getValues();
    	lowest = findLowest();
    
    	
    	ave0 = CalcAvarage(v1, v2, v3, v4, v5);
    
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Precompiled headers are a nice feature where it compiles all your common header files only ONCE so that compile times are smaller. Just add this into your stdafx.h file:
    Code:
    #include <iostream>
    using namespace std;
    ... and in every single file you have in your project, make sure it includes "stdafx.h" Put all your common includes in there and you don't have to include them again in your seperate files.

    You can turn this feature off by browsing though options or making a new project without precompiled headers (empty project).

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    It is working,

    I came back to post the program after I fix it, and I find the same solution.

    Thank you for your help.
    Code:
    #include <iostream.h>
    #include <math.h>
    
    float v1,v2,v3,v4,v5;
    
    void getValues()
    {
    
    	cout<<" Please enter the first Value: " ;
    	cin>> v1;
    
    	cout<<" Please enter the secod Value: " ;
    	cin>> v2;
    
    	cout<<" Please enter the Third Value: " ;
    	cin>> v3;
    
    	cout<<" Please enter the Fourth Value: " ;
    	cin>> v4;
    
    	cout<<" Please enter the Fifth Value: " ;
    	cin>> v5;
    
    }
    
    
    float CalcAvarage (float v01, float v02,  float v03, float v04, float v05)
    {
    
    	float ave;
    	float total= 0;
    	float scores[5];
    	float temp;
    
    	scores[0]= v01;
    	scores[1]= v02;
    	scores[2]= v03;
    	scores[3]= v04;
    	scores[4]= v05;
    	
    	for (int i=0; i<5; i++)
    		for ( int j= i+1; j<5; j++)
    			if( scores[i] <= scores[j]){
    				temp = scores[i]; 
    				scores[i]= scores[j]; 
    				scores[j] = temp;
    			}// end if
    
    	
    	for(int k =0; k<4; k++)
    	 total = total + scores[k];  
    	
        cout<< "total points = "<<total ;
    	ave = total / 4;
    
    
    return ave ;
    }
    
    
    float findLowest ()
    {
    
    	float lowest;
    	
    	lowest= v1;
    	if (lowest >= v2)
    		lowest =  v2;
    	if (lowest >= v3)
    		lowest =  v3;
    	if (lowest >= v4)
    		lowest  = v4;
    	if (lowest >= v5)
    		lowest =  v5;
    return lowest;
    }
    
    int main()
    {
    
    	float ave0;
    	float lowest;
    	
    	getValues();
    
    	lowest = findLowest();
    	cout<<endl<<endl;
    	cout<<" The lowest score is :"<< lowest<<" Points" <<endl;
    	
    	ave0 = CalcAvarage(v1, v2, v3, v4, v5);
    	cout<<" The avarage of the four highest Four scores is:" << ave0<<" Points"<< endl;
    	
    	int x;
    	cin>>x;
    return 0;
    }
    But what is about the using namespace std;
    why I should use it with this program?
    C++
    The best

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Thank you for the infor about namespacing.

    Thank you about the information about name spacing.

    I am ganna close this thread now.
    C++
    The best

  7. #7
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    Go on then, close it..hehe
    Such is life.

Popular pages Recent additions subscribe to a feed

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