Help with a function.
-
Hello, I am having a problem with a function. I am trying to increment a variable (odometer) using the speed and distance traveled. Below is what I have. Any suggestions are appreciated. Thanks, Eric
void drive( int, int ); // this is in the class (header file) void Car::drive( int spd, int minutes ) //implementation file { int remainderMinutes = 0; int hours; int distance; system( "CLS" ); while( minutes > 60 ) { remainderMinutes += minutes % 60 * oneDividedBySixty; minutes += remainderMinutes; } hours = minutes * oneDividedBySixty; distance = spd * minutes; cout << "\n\n The distance is " << distance << "."; cout << "\n\n The speed is " << speed << "."; cout << "\n\n The time is " << minutes << " minutes."; } int main() { Car c; char choice; do { cout << "\n\n\n Please make a selection from the menu.\n\n"; cout << "\n Press 'D' to display the car attributes.\n"; cout << "\n Press 'R' to reset the car attributes.\n"; cout << "\n Press 'X' to exit the program.\n"; cin >> choice; choice = toupper( choice ); switch( toupper( choice ) ) { case 'D': c.printCar(); break; case 'R': c.reset(); break; case 'X': break; default: cout << "\n Unknown choice entered.\n" << " Enter a new choice.\n\n"; break; } } while ( choice != 'X' ); c.reset(); c.printCar(); //c.getSpeed(); //c.getMinutes(); c.drive( c.getSpeed(), c.getMinutes() ); //c.drive( speed, minutes ); cout << "\n\n\n "; return 0; }
-
Hello, I am having a problem with a function. I am trying to increment a variable (odometer) using the speed and distance traveled. Below is what I have. Any suggestions are appreciated. Thanks, Eric
void drive( int, int ); // this is in the class (header file) void Car::drive( int spd, int minutes ) //implementation file { int remainderMinutes = 0; int hours; int distance; system( "CLS" ); while( minutes > 60 ) { remainderMinutes += minutes % 60 * oneDividedBySixty; minutes += remainderMinutes; } hours = minutes * oneDividedBySixty; distance = spd * minutes; cout << "\n\n The distance is " << distance << "."; cout << "\n\n The speed is " << speed << "."; cout << "\n\n The time is " << minutes << " minutes."; } int main() { Car c; char choice; do { cout << "\n\n\n Please make a selection from the menu.\n\n"; cout << "\n Press 'D' to display the car attributes.\n"; cout << "\n Press 'R' to reset the car attributes.\n"; cout << "\n Press 'X' to exit the program.\n"; cin >> choice; choice = toupper( choice ); switch( toupper( choice ) ) { case 'D': c.printCar(); break; case 'R': c.reset(); break; case 'X': break; default: cout << "\n Unknown choice entered.\n" << " Enter a new choice.\n\n"; break; } } while ( choice != 'X' ); c.reset(); c.printCar(); //c.getSpeed(); //c.getMinutes(); c.drive( c.getSpeed(), c.getMinutes() ); //c.drive( speed, minutes ); cout << "\n\n\n "; return 0; }
You should start by describing what your problem is. SkyWalker
-
You should start by describing what your problem is. SkyWalker
My problem is that the remainderMinutes equation is not working correctly. Thank you, Eric
-
My problem is that the remainderMinutes equation is not working correctly. Thank you, Eric
How did you declare (and initialize)
oneDividedBySixty
? SkyWalker -- modified at 8:32 Sunday 23rd October, 2005 -
My problem is that the remainderMinutes equation is not working correctly. Thank you, Eric
OK, after tracing my code, I have fixed my previous problems (I think). As of now, my two main concerns are: 1.) Making sure I convert the ints to floats correctly (where needed). 2.) Figuring out what is going on with my destructor (this is all new to me). Every time I run the program with the destructor, I get an ENTERNAL COMPILER ERROR. I really appreciate the feedback and suggestions! Thanks, Eric Here is my program:
//--------------------------------------------------------------------------- //------------------------Header.h--------------------------------------- #ifndef HEADER_H #define HEADER_H class Car { public: Car(); Car( int, string, string, string, string, int ); //~Car(); void setYear( int ); void setManufacturer( string ); void setModel( string ); void setColor( string ); void setCondition( string ); void setOdometer( int ); int getYear(); string getManufacturer(); string getModel(); string getColor(); string getCondition(); int getOdometer(); void printYear(); void printManufacturer(); void printModel(); void printColor(); void printCondition(); void printOdometer(); int getMinutes(); int getSpeed(); void drive( int, int ); void newCar(); void displayOdometer(); void reset(); void setCar( int, string, string, string, string, int ); void printCar(); private: int year; string manufacturer; string model; string color; string condition; int odometer; int speed; int minutes; }; #endif //-------------------------------------------------------------------------------- //-------------------------Implementation.cpp------------------------------ #include #include #include using namespace std; #include "Header.h" Car::Car() { system( "CLS" ); year = 9999; manufacturer = "NoManufacturerYet"; model = "NoModelYet"; color = "NoColorYet"; condition = "NoConditionYet"; odometer = 999999999; } Car::Car( int newYear, string newManufacturer, string newModel, string newColor, string newCondition, int newOdometer ) { system( "CLS" ); year = newYear; manufacturer = newManufacturer; model = newModel; color = newColor; condition = newCondition; odometer = newOdometer; } /* Car::~Car { cout << "\n\n The destructor has been called.\n\n"; } */ void Car::setYear( int yr ) { system( "CLS" ); year = yr; } void Car::setManufacturer( string manufa
-
OK, after tracing my code, I have fixed my previous problems (I think). As of now, my two main concerns are: 1.) Making sure I convert the ints to floats correctly (where needed). 2.) Figuring out what is going on with my destructor (this is all new to me). Every time I run the program with the destructor, I get an ENTERNAL COMPILER ERROR. I really appreciate the feedback and suggestions! Thanks, Eric Here is my program:
//--------------------------------------------------------------------------- //------------------------Header.h--------------------------------------- #ifndef HEADER_H #define HEADER_H class Car { public: Car(); Car( int, string, string, string, string, int ); //~Car(); void setYear( int ); void setManufacturer( string ); void setModel( string ); void setColor( string ); void setCondition( string ); void setOdometer( int ); int getYear(); string getManufacturer(); string getModel(); string getColor(); string getCondition(); int getOdometer(); void printYear(); void printManufacturer(); void printModel(); void printColor(); void printCondition(); void printOdometer(); int getMinutes(); int getSpeed(); void drive( int, int ); void newCar(); void displayOdometer(); void reset(); void setCar( int, string, string, string, string, int ); void printCar(); private: int year; string manufacturer; string model; string color; string condition; int odometer; int speed; int minutes; }; #endif //-------------------------------------------------------------------------------- //-------------------------Implementation.cpp------------------------------ #include #include #include using namespace std; #include "Header.h" Car::Car() { system( "CLS" ); year = 9999; manufacturer = "NoManufacturerYet"; model = "NoModelYet"; color = "NoColorYet"; condition = "NoConditionYet"; odometer = 999999999; } Car::Car( int newYear, string newManufacturer, string newModel, string newColor, string newCondition, int newOdometer ) { system( "CLS" ); year = newYear; manufacturer = newManufacturer; model = newModel; color = newColor; condition = newCondition; odometer = newOdometer; } /* Car::~Car { cout << "\n\n The destructor has been called.\n\n"; } */ void Car::setYear( int yr ) { system( "CLS" ); year = yr; } void Car::setManufacturer( string manufa
Does anyone know what the INTERNAL COMPILER ERROR means?
--------------------Configuration: Implementation - Win32 Debug-------------------- Compiling... Implementation.cpp I:\Documents and Settings\Implementation.cpp(48) : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1794) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information Main.cpp Error executing cl.exe. Implementation.exe - 1 error(s), 0 warning(s)
I found this http://owlnext.sourceforge.net/qa51.html[^]. The site says, "This error occurs only on machines with the Windows 95 or Windows 98 operating system." But I am running Win XP Home w/SP2. I'm puzzled. Thanks, Eric -
Does anyone know what the INTERNAL COMPILER ERROR means?
--------------------Configuration: Implementation - Win32 Debug-------------------- Compiling... Implementation.cpp I:\Documents and Settings\Implementation.cpp(48) : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1794) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information Main.cpp Error executing cl.exe. Implementation.exe - 1 error(s), 0 warning(s)
I found this http://owlnext.sourceforge.net/qa51.html[^]. The site says, "This error occurs only on machines with the Windows 95 or Windows 98 operating system." But I am running Win XP Home w/SP2. I'm puzzled. Thanks, EricOops, nevermind the INTERNAL COMPILER ERROR. I forgot a set of parenthesis (see http://lithiumdata.com/QandA/compileerror.htm[^]). Originally I had:
Car::~Car { cout << "\n\n The destructor has been called.\n\n"; }
Here is what it needs to be:Car::~Car() { cout << "\n\n The destructor has been called.\n\n"; }
Thanks, Eric