So the problem is that I am trying to use the variable speed
in a for loop. The error I'm given is: Uninitialized local variable 'speed' used. The strange thing is that I already declared speed as an int before.
I'm including the header file, and the 2 other files associated with this project. Since there are multiple files involved, I'm using a link to pastebin for all of them, but the UseCar.cpp code will be here as well.
Car.h http://pastebin.com/xn8dnzrH
Car.cpp http://pastebin.com/QYrXDMfe
UseCar.cpp http://pastebin.com/GX8j2vPU
#include "stdafx.h"
#include "Car.h"
#include "Car.cpp"
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(){
Car dealer;// Creates a new Car object
int yearModel;// Local variables for model year
int speed;// Local variables for speed
string make;// Names are kept the same to avoid confusion
// Calls the accelerate function 5 times and displays the results after each iteration
for (int i = 0; i < 5; ++i){
dealer.accelerate(speed);
cout << "The current speed is: " << dealer.getSpeed() << endl;
}
cout << "We are now braking the car" << endl;
// Calls the brake function 5 times and displays the results after each iteration
for (int i = 0; i < 5; ++i){
dealer.brake(speed);
cout << "The current speed is: " << dealer.getSpeed() << endl;
}
}