Hey guys, I follow Ivan through the video and I feel I have a pretty good understanding of loops in general. Here is the code reprinted exactly from the video and I wanted to see if anyone could find the error. The code is supposed to print the total amount of miles of all three cars and yet it prints a new line after adding one at a time with the new total each time the loops iterates.
Here is what I have… (note: you can see I attempted Ivan’s tip on printing for every counter to track each iteration but that did not help my cause)
int main()
{
int numberOfCars = 3;
int carMiles [] = {15, 13, 15};
// total number of miles for all cars
//notice*** accessing carMiles[counter] = carMiles[0] aka first in the array
int totalMiles = 0;
for(int counter = 0; counter < numberOfCars; counter++){
cout<<"counter is now "<<counter<<endl;
totalMiles += carMiles[counter];
cout << "Total miles of all cars is "<<totalMiles<<endl;
}
Thank you!