within my code i'm supposed to create a code where i get the speed of a car and add 5 to that speed with each loop and then display the value after each loop finishes, so far it only displays the number i originally put it. i think i messed up somewhere with the accessors and mutators
#include "Car.h"
#include <string>
#include <iostream>
usingnamespace std;
int main()
{
/*declarations*/
Car obj;
int year;
double speed;
string make;
bool test = true;
do {
cout << "please enter the speed of the car: ";
cin >> speed;
if (speed < 0)
{
cout << "invalid number, please type in a numbe above 0" << endl << endl;
test = false;
}
elseif (speed > 0)
{
test = true;
}
} while (test == false);
do {
cout << "please enter the year of the carr (yyyy): ";
cin >> year;
if (year < 1886)
{
cout << "please type in a year past 1886" << endl << endl;
test = false;
}
elseif (year > 1886)
{
test = true;
}
} while (test == false);
cout << "please enter the make name of the car: ";
getline(cin, make);
cin.ignore();
obj.setValues(speed, year, make);
for (int i = 0; i < 5; i++)
{
obj.accelerateFunction();
cout << "the current speed is: " << speed << endl;
}
system("pause");
return 0;
}
how do i make the destructor's message show at the end of the main.cpp?
Open up a command prompt console window and run your app from that window. When your app exits the window won't close.
If you are running Windows 10 you can easily start a command prompt window in Windows File Explorer. Navigate to the directory where your program's exe file is located and in File Explorer's address bar type "cmd" and hit enter.
The command prompt window automatically has the location set so all you have to do is type the name of your program file.
i figured out that the system("pause") was stopping my destructor from showing up. i know there's some talk about not using that line of code unless you're using it for homework or etc. what's a work around for that? for now i just added a breakpoint at the curly brace of end of int main() brace and i saw my destructor message
Using any system command is "iffy." They are specific to the OS. What works for Windows may not work with Mac or *nix.
There are other "beginner" things that can end up causing difficulties later, such as "using namespace std;" Not, it is not wrong or bad, just not recommended.