Thread: Need help with one error in my code

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Unhappy Need help with one error in my code

    I have this one last error in my code. Could someone please help me? Here is my code:

    //Implementation file for CarFacts application

    #include <iostream.h>
    #include "vehicle.h" // [The error highlights this line but I switched the qoutes to "<>" and it still doesn't work]

    int main()
    {
    char firstName[20], lastName[20];
    cout << "Please input your first and last name.\n";
    cin >> firstName >> lastName;
    cout << firstName << " , welcome to the RJ CarFacts database.\n\n";
    cout << "The database will allow you to acquire vehicle info based on specs you define.\n";
    }
    Thanks,
    RJ

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Smile Oops, sorry 'bout that.

    The error is:

    c:\dev-c++\vehicle.h:3 unterminated '#if" conditional


    The header file is:

    // header file - vehicle
    #include<iostream.h>
    #ifndef VEHICLE_H
    #define VEHICLE_H

    class vehicle //base class declaration
    {

    private:
    int itsDoors;
    int itsCylinders;
    int itsEngineSize;
    int itsWheels;
    float wheelWeight;

    };

    void InputCarInfo (vehicle buildCar)
    {
    cout << "How many doors would you like.\n";
    cin >> buildCar.itsDoors;
    cout << "How many cylinders do you want\n";
    cin >> buildCar.itsCylinders;
    cout << "How many wheels do you need on the vehicle\n\n";
    cin >> buildCar.itsWheels;
    }

    void DisplayCarInfo (vehicle yourCar)
    {
    cout << "The vehicle you built has " << yourCar.itsDoors << " doors, " << yourCar.itsCylinders << " cylinders, and " << yourCar.itsWheels << " wheels.\n";
    }
    Thanks,
    RJ

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > #ifndef VEHICLE_H
    You've got this at the start of the file

    So you need
    #endif
    at the end of the file.

    Later on, you will want to move those functions into vehicle.cpp
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Smile very much appreciate your help (solution), however, still got same error.

    I tried as you suggested but to no avail, I still got the same error. I do really appreciate all the help, though. Is there any other possible solutions for this error?

    Again, appreciate any feedback you have.
    Thanks,
    RJ

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I tried as you suggested but to no avail,
    You put a
    &nbsp; #endif
    at the end of your .h file and got the same error

    You did save the file didn't you?

    I would suggest you use the board 'attach file' feature and upload vehicle.h.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Smile I'll have to do that in a new thread

    When replying is says I cannot upload attachment so I will use a new thread to do this.
    Thanks,
    RJ

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Code:
    #include<iostream.h> 
    #ifndef VEHICLE_H 
    #define VEHICLE_H 
    
    class vehicle //base class declaration 
    { 
    
    private: 
    int itsDoors; 
    int itsCylinders; 
    int itsEngineSize; 
    int itsWheels; 
    float wheelWeight; 
    
    }; 
    
    void InputCarInfo (vehicle buildCar) 
    { 
    cout << "How many doors would you like.\n"; 
    cin >> buildCar.itsDoors; 
    cout << "How many cylinders do you want\n"; 
    cin >> buildCar.itsCylinders; 
    cout << "How many wheels do you need on the vehicle\n\n"; 
    cin >> buildCar.itsWheels; 
    } 
    
    void DisplayCarInfo (vehicle yourCar) 
    { 
    cout << "The vehicle you built has " << yourCar.itsDoors << " doors, " << yourCar.itsCylinders << " cylinders, and " << yourCar.itsWheels << " wheels.\n"; 
    }
    This cannot work properly because you are trying to use private data as if it were public.

    for instance look at this line....

    cin >> buildCar.itsDoors;

    buildCar.itsDoors is private to the class so you have no access to it from outside of the class unless you make it public or add accessor/mutator functions to your class.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM