Hello I'm having trouble displaying the contents of an array. Heres my code and I cant seem to find the problem
// C++ program to fractions
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Structure declaration
struct Car
{
string carMake;
string carModel;
int yearModel;
double cost;
};
// Function Protocols
void getCar(Car &);
void printCar(Car);
int main()
{
const int SIZE = 3;
Car arrCar[SIZE] = {
{"Ford", "Mustang", 2968, 20300},
{0,0,0,0},
{0,0,0,0},
};
int index;
cout << "Please input the info of car" << endl;
for (index = 1; index < SIZE; index++)
{
getCar(arrCar[index]);
}
// printCar function is called
printCar(arrCar[index]);
return 0;
}
// getCar function prompts user to input the information for the car
void getCar(Car &temp)
{
//Car temp;
cout << "Enter Make: ";
getline(cin, temp.carMake);
cout << "Enter Model: ";
cin >> temp.carModel;
cout << "Enter Year: ";
cin >> temp.yearModel;
cout << "Enter Cost: ";
cin >> temp.cost;
cout << endl;
// return temp;
}
// printCar function displays the information of the car*
void printCar(Car temp)
{
for (int index = 0; index < 3; index++)
Thanks a bunch for the feedback fellas. @keskiverto it was deliberately because I wanted the mustang to go first. @lastchance I appreciate your input my friend. I noticed I had to put another loop for the print function and had to put quotes around the first two elements of my array. And yes I will put more code tags!