I'm trying to write a code for the following prompt; Demonstrate the class in a program that creates a Car object, and then calls the accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it. Then, call the brake function five times. After each call to the brake function, get the current speed of the car and display it.
The problem I'm having is its only showing negative speeds and its cycling through 25 times, it should only display the speed 10 times. Someone please help this coding novice!
^^ What they said. You're calling brake on line 54, but you never defined it. If you look on line 49 you called accelerate, and you defined it on line 30.
Edit: lol my line numbers seem to be a bit off.. fail
I ended up editing the entire post before I saw that all of you had responded. Now my current issue is its displaying the speed 25 times instead of 10 times AND all the speeds are negative. The times should display as such 5, 10, 15, 20, 25, 20, 15, 10, 5, 0
My tip for when you're dealing with classes, @OP. Always implement your class methods. It doesn't matter if they're just barebones, like if you had a function that returned an int:
1 2 3 4
int foo( int a )
{
return 0;
}
Just do that. It won't do what you want, but you won't get linker errors this way. There's other things that'll get you linker errors like including header files repeatedly (although there is a way), etc.