I am trying to make this program to give me the cheapest price of the cars within the array. When I compile and run it, I do get the cheapest price. However, the message does not appear which should say the price of this car is cheapest and stuff (as you can see in the code below). Moreover, the program crashes. Please help.
HOW DO I DO THE FOLLOWING QUESTIONS?
8. CHANGE this program so that it now displays the information about the cheapest car in the array.
9. CHANGE this program so that it now displays the information about the one with the smallest engine in the array.
10. CHANGE this program so that it displays the information about the most expensive, the least expensive and the smallest engine. That is, it displays stuff about 3 different cars at the end. You will need to think carefully about all the data your program needs to remember while looping through the array.
// Session6.cpp : Defines the entry point for the console application.
#include <iomanip> // only used to tidy up the console output here
using namespace std;
const int MAXCARS =5; //Always use this instead of magic numbers in code!
// initialise to the details of first in array
PriceMostCheap = Price[IndexMostCheap];
// display a header line - note use of \t for tabs to try to line up - not successful, but I'm not bothered
cout<<"Model"<<"\t\tReg Num"<<"\tPrice"<<"\tEngine Size"<<endl;
// note use here of iomanip functions to set the width of EACH field (eg 10 chars) and filling the spare with ' '
// this makes for a nicer alignment than the commented out line which gets messed up by the Lamborghini gallardo
for (int i=0; i<MAXCARS; i--)
// now find out of this car is the most expensive
IndexMostCheap =i; //update this index
PriceMostCheap = Price[i]; //update this price
// gone through all the cars.
// now can display details about most expensive car
cout<<"Most cheapest Car is "<<ModelName[IndexMostCheap]<<" at a price of "<<Price[IndexMostCheap]<<endl;
cout<<"With reg num of "<<Registration[IndexMostCheap]<<" and engine size of "<<EngineSize[IndexMostCheap]<<endl;