I have to ask user to input information on a car such as make, model, year, etc. After that, I need to display the user input AND display three more already initialized car structure variables. My problem is that my program is asking multiple times instead of just once. And it's not displaying the initialized array list. Also I'm able to input the purpose, but it doesn't display!! Here is my code! Urgent help is needed. I tried my best but I'm slowly giving up and going crazy. Not letting me putting it in code format.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// enumerated type to hold purpose of car
enum Purpose {BUSINESS, PERSONAL};
// Car structure definition
struct Car
{
string carMake;
string carModel;
int yearModel;
double cost;
Purpose purpose;
};
// function prototypes
Car getCarInfo();
void displayCar(Car c);
int main()
{
//using structure
Car car;
// get car information
car = getCarInfo();
// display student information
displayCar(car);
//using array of structure variables
Car carArray[10];
carArray[0] = { "Ford", "Taurus", 1997, 21000.00, BUSINESS };
carArray[1] = { "Honda", "Accord", 1992, 11000.00, BUSINESS };
carArray[2] = { "Lamborghini", "Aventador", 2001, 390000.00, PERSONAL };
carArray[3] = getCarInfo();
//store new values in carArray[4]
//carArray[10] = getCarInfo();
// display car information
//cout << "carArray[10]:\n";
//displayCar(carArray[10]); // using Car array variable
// display member values
getCarInfo();
cout << endl;
for (int i = 0; i < 4; i++)
displayCar(carArray[i]);
return 0;
}
Car getCarInfo() {
//int year;
int purpose;
//Car s;
Car c1;
cout << "\nGetting car data...\n";
cout << endl;
cout << "Make: ";
getline(cin, c1.carMake);
cout << "Model: ";
cin >> c1.carModel;
cout << "Year: ";
cin >> c1.yearModel;
cout << "Cost: ";
cin >> c1.cost;
//get the purpose of the car
cout << "Purpose(1-BUSINESS, 2-PERSONAL): ";
cin >> purpose;
c1.purpose = static_cast<Purpose>(purpose);
//clear out the stream
cin.ignore(100, '\n');
// return the car variable
return c1;
}
// function with Car parameter to
// display Car Structure data members
void displayCar(Car c) {
cout << "\n**Car Information**\n";
cout << "Make: " << c.carMake << endl;
cout << "Model: " << c.carModel << endl;
cout << "Year: " << c.yearModel << endl;
cout << fixed << setprecision(2);
cout << "Cost: " << c.cost << endl;
// adding enumerated type
cout << "Purpose: ";
}
***HOW OUTPUT SHOULD LOOK LIKE***
Getting Car Information...