Fatal error C1010: unexpected end of file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shashahayes
    New Member
    • Mar 2010
    • 13

    Fatal error C1010: unexpected end of file

    This is the message I am getting when I try to compile it.

    fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

    Code:
    // Furniture.cpp - This program calculates prices for custom made tables.
    
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
         double Charge = 0.0;
       	 double Length = 50;
         double Width = 40;
       	 double Area = 0.0;
         string wood type = 'oak';	
    	 string wood type = 'mahogany';
         string wood type = 'pine';
       	 double leaves = 2; 	 
       
    	  const int charge = 150.00
    	  if area  > 750 then charge = 200
    	  if wood type = mahogany then charge 350
    	  if wood type = oak then charge = 250
    	  if leaves = #*50 + charge
    		
    
       
    			
       // Output charge for this table
       cout << "The charge for this table is $" << charge << endl;
       return(0); 
    }
    }

    1> Add directive to 'stdafx.h' or rebuild precompiled header
    1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(31) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
    1>Build log was saved at "file://c:\Users\JimSha \Documents\Visu al Studio 2008\Projects\f urniture\furnit ure\Debug\Build Log.htm"
    1>furniture - 1 error(s), 2 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your variable names are not allowed to have spaces: wood type. Use woodtype or WoodType pr wood_type.

    Also, your if statements are not correct. The condition has to be in parentheses.

    Code:
    if (A == 3) etc.....
    not

    Code:
    if A == 3

    Comment

    • shashahayes
      New Member
      • Mar 2010
      • 13

      #3
      Thank you so much. I am having alot of trouble and I appreciate all your help!

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You have created a Windows Console Application rather than a Console Application.

        The easiest thing for a beginner is to create a new project as follows:

        1) Create a Win32 project.
        2) When the wizard appears DO NOT CLICK FINISH.
        3) Instead, click Application Settings
        4) Select: Console Application and Empty Project
        5) Click Finish.

        This removes the stdafx.h and pre-compiled header requirements.

        BTW: When you run the program be sure to use Start Without Debugging. That will cause VC++ to stop execution at the end of main() so you can see what happened. If you just Start, all you will see is a black flash as your program executed. You select Start when you are using your debugger.

        Comment

        • shashahayes
          New Member
          • Mar 2010
          • 13

          #5
          Thanks again. I got past the intial problem with your help. Now I am getting a different message. If you could add some insight to what I am doing wrong I would really appreciate it !

          1>------ Build started: Project: Furniture, Configuration: Debug Win32 ------
          1>Compiling...
          1>stdafx.cpp
          1>Compiling...
          1>Furniture.cp p
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(19) : error C2440: 'initializing' : cannot convert from 'int' to 'std::basic_str ing<_Elem,_Trai ts,_Ax>'
          1> with
          1> [
          1> _Elem=char,
          1> _Traits=std::ch ar_traits<char> ,
          1> _Ax=std::alloca tor<char>
          1> ]
          1> No constructor could take the source type, or constructor overload resolution was ambiguous
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(20) : error C2374: 'wood_type' : redefinition; multiple initialization
          1> c:\users\jimsha \documents\visu al studio 2008\projects\f urniture\furnit ure\furniture.c pp(19) : see declaration of 'wood_type'
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(20) : error C2015: too many characters in constant
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(21) : error C2374: 'wood_type' : redefinition; multiple initialization
          1> c:\users\jimsha \documents\visu al studio 2008\projects\f urniture\furnit ure\furniture.c pp(19) : see declaration of 'wood_type'
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(21) : error C2440: 'initializing' : cannot convert from 'int' to 'std::basic_str ing<_Elem,_Trai ts,_Ax>'
          1> with
          1> [
          1> _Elem=char,
          1> _Traits=std::ch ar_traits<char> ,
          1> _Ax=std::alloca tor<char>
          1> ]
          1> No constructor could take the source type, or constructor overload resolution was ambiguous
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(25) : warning C4244: 'initializing' : conversion from 'double' to 'const int', possible loss of data
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(25) : error C2143: syntax error : missing ';' before 'if'
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(25) : error C2061: syntax error : identifier 'area'
          1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(28) : error C2014: preprocessor command must start as first nonwhite space
          1>Build log was saved at "file://c:\Users\JimSha \Documents\Visu al Studio 2008\Projects\F urniture\Furnit ure\Debug\Build Log.htm"
          1>Furniture - 8 error(s), 1 warning(s)
          ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(19 ) : error C2440: 'initializing' : cannot convert from 'int' to
            The compiler got in trouble on lin 19 of furniture.cpp.

            What is that line? The error is there or it is earlier than line 19.

            The other errors are irrelevant. Often these are caused as a result iof the first error.

            What you do is fix the first error and rebuild. Then fix the first error and rebuild. Etc... At some point all the subsequent errors just vanish.

            Comment

            • shashahayes
              New Member
              • Mar 2010
              • 13

              #7
              Here is what I got now, I changed the wood type to WoodType and I still get an error.

              Code:
              // Furniture.cpp : Defines the entry point for the console application.
              //
              
              #include "stdafx.h"
              
              
              // Furniture.cpp - This program calculates prices for custom made tables.
              
              #include <iostream>
              #include <string>
              using namespace std;
              int main()
              
              {
                   double Charge = 0.0;
                 	 double Length = 50;
                   double Width = 40;
                 	 double Area = 0.0;
                   string WoodType = 'oak';	
              	 string WoodType = 'mahogany';
                   string WoodType = 'pine';
                 	 double leaves = 2; 	 
                 
              	  const int charge = 150.00
              	  if area  > 750 then charge = 200
              	  if WoodTyp = mahogany then charge 350
              	  if WoodType = oak then charge = 250
              	  if leaves = #*50 + charge
              		
              
                 
              			
                 // Output charge for this table
                 cout << "The charge for this table is $" << charge << endl;
                 return(0); 
              }
              This is what I get for errors.
              Code:
              1>------ Build started: Project: Furniture, Configuration: Debug Win32 ------
              1>Compiling...
              1>Furniture.cpp
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(19) : error C2440: 'initializing' : cannot convert from 'int' to 'std::basic_string<_Elem,_Traits,_Ax>'
              1>        with
              1>        [
              1>            _Elem=char,
              1>            _Traits=std::char_traits<char>,
              1>            _Ax=std::allocator<char>
              1>        ]
              1>        No constructor could take the source type, or constructor overload resolution was ambiguous
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(20) : error C2374: 'WoodType' : redefinition; multiple initialization
              1>        c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(19) : see declaration of 'WoodType'
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(20) : error C2015: too many characters in constant
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(21) : error C2374: 'WoodType' : redefinition; multiple initialization
              1>        c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(19) : see declaration of 'WoodType'
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(21) : error C2440: 'initializing' : cannot convert from 'int' to 'std::basic_string<_Elem,_Traits,_Ax>'
              1>        with
              1>        [
              1>            _Elem=char,
              1>            _Traits=std::char_traits<char>,
              1>            _Ax=std::allocator<char>
              1>        ]
              1>        No constructor could take the source type, or constructor overload resolution was ambiguous
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(25) : warning C4244: 'initializing' : conversion from 'double' to 'const int', possible loss of data
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(25) : error C2143: syntax error : missing ';' before 'if'
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(25) : error C2061: syntax error : identifier 'area'
              1>c:\users\jimsha\documents\visual studio 2008\projects\furniture\furniture\furniture.cpp(28) : error C2014: preprocessor command must start as first nonwhite space
              1>Build log was saved at "file://c:\Users\JimSha\Documents\Visual Studio 2008\Projects\Furniture\Furniture\Debug\BuildLog.htm"
              1>Furniture - 8 error(s), 1 warning(s)
              ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
              Thanks agaian, I know this must seem elementry to you but I am really confused

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                Look at this code:

                Code:
                string WoodType = 'oak';

                A literal string needs double quotes rather than single quotes. Single quotes are for single characters.

                Try:

                Code:
                string WoodType = "oak";
                Also, there is one place wheere you have WoodTyp rather than WoodType.

                Gotta be careful. The compiler is really fussy.

                Comment

                • shashahayes
                  New Member
                  • Mar 2010
                  • 13

                  #9
                  I got past the string problem. Thanks I don't how it would have took me without your help!!! Now my problem has moved down to line 25, 26, 28. Do you see what I did wrong?

                  Code:
                  // Furniture.cpp - This program calculates prices for custom made tables.
                  
                  #include <iostream>
                  #include <string>
                  using namespace std;
                  int main()
                  
                  {
                       double Charge = 0.0;
                     	 double Length = 50;
                       double Width = 40;
                     	 double Area = 0.0;
                       string WoodType1 = "'oak'";	
                  	 string WoodType2 = "'mahogany'";
                       string WoodType3 = "'pine'";
                     	 double leaves = 2; 	 
                     
                  	  const double charge = 150.00
                  	  if area  > 750 than charge = 200
                  	  if WoodType2 = mahogany then charge 350
                  	  if WoodType1 = oak then charge = 250
                  	  if leaves = #*50 + charge
                  		
                  
                     
                  			
                     // Output charge for this table
                     cout << "The charge for this table is $" << charge << endl;
                     return(0); 
                  }
                  Here are the errors now.

                  1>Compiling...
                  1>Furniture.cp p
                  1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(25) : error C2143: syntax error : missing ';' before 'if'
                  1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(25) : error C2061: syntax error : identifier 'area'
                  1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(28) : error C2014: preprocessor command must start as first nonwhite space
                  1>Build log was saved at "file://c:\Users\JimSha \Documents\Visu al Studio 2008\Projects\F urniture\Furnit ure\Debug\Build Log.htm"
                  1>Furniture - 3 error(s), 0 warning(s)
                  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

                  Comment

                  • shashahayes
                    New Member
                    • Mar 2010
                    • 13

                    #10
                    I only have one error now and I don't know what is causing it. Do you have any ideas?

                    Code:
                    // Furniture.cpp : Defines the entry point for the console application.
                    //
                    
                    #include "stdafx.h"
                    
                    
                    // Furniture.cpp - This program calculates prices for custom made tables.
                    
                    #include <iostream>
                    #include <string>
                    using namespace std;
                    int main()
                    
                    {
                         double Charge = 0.0;
                       	 double Length = 50;
                         double Width = 40;
                       	 double area = 0.0;
                         string WoodType1 = "'oak'";	
                    	 string WoodType2 = "'mahogany'";
                         string WoodType3 = "'pine'";
                       	 double leaves = 2; 	 
                       
                    	  const double charge = 150.00;
                    	  if area > 750 then charge = 200
                    	  if "WoodType2" = then charge 350
                    	  if "WoodType1" = then charge = 250
                    	  if leaves = number * 50 + charge
                    		
                    
                       
                    			
                       // Output charge for this table
                       cout << "The charge for this table is $" << charge << endl;
                       return(0);
                    1>------ Build started: Project: Furniture, Configuration: Debug Win32 ------
                    1>Compiling...
                    1>Furniture.cp p
                    1>c:\users\jims ha\documents\vi sual studio 2008\projects\f urniture\furnit ure\furniture.c pp(25) : error C2061: syntax error : identifier 'area'
                    1>Build log was saved at "file://c:\Users\JimSha \Documents\Visu al Studio 2008\Projects\F urniture\Furnit ure\Debug\Build Log.htm"
                    1>Furniture - 1 error(s), 0 warning(s)
                    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

                    Comment

                    • weaknessforcats
                      Recognized Expert Expert
                      • Mar 2007
                      • 9214

                      #11
                      Please read about syntax before you try to use it.

                      I said in an earlier post that an if statement has the condition inside parentheses:

                      Code:
                      if (Test == true)
                      {
                      
                      }
                      and not

                      Code:
                      if Test == true
                      {
                      
                      }
                      Carefully look at your code.

                      Comment

                      Working...