Using Struct

Who can help.....my program won't run at all...I tried everything possible...what am I missing...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct Date
{
int month;
int day;
int year;
};
struct Car
{
double price;
Date purchased;
string customer;
};
void GetCar (ifstream& dataIn, Car& car)
{
dataIn >> car.customer;
dataIn >> car.price >> car.purchased.day
>> car.purchased.month >> car.purchased.year;
dataIn.ignore (2, '\n');
}
void WriteCar (ofstream& dataOut, Car car)
{
dataOut << "Customer; " << car.customer << endl
<< "Price: " << car.price << endl
<< "Purchashed: " << car.purchased.day << "/"
<< car.purchased.month << "/"
<< car.purchased.year << endl;
}

int main ()
{
Car car;
ifstream dataIn;
ofstream dataOut;
dataIn.open ("cars.dat");
dataOut.open ("cars.out");
cout << fixed << showpoint;

GetCar (dataIn.car);
while (dataIn)
{
car.price = car.price * 1.10;
WriteCar (dataOut, car);
Getcar (dataIn, car);
}
return 0;
}
And the errors are?
------ Build started: Project: Projects, Configuration: Debug Win32 ------
Compiling...
Cars.cpp
..\..\..\..\..\Desktop\Cars.cpp(43) : error C2039: 'car' : is not a member of 'std::basic_ifstream<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
..\..\..\..\..\Desktop\Cars.cpp(43) : error C2660: 'GetCar' : function does not take 1 arguments
..\..\..\..\..\Desktop\Cars.cpp(48) : error C3861: 'Getcar': identifier not found
Build log was saved at "file://c:\Documents and Settings\Darren\My Documents\Visual Studio 2008\Projects\Projects\Projects\Debug\BuildLog.htm"
Projects - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
closed account (S6k9GNh0)
I know!

1. car isn't an ofstream which is what the function requires.
2. Car() takes more than one argument!
3. C++ is case sensitive.

You have a long way to go with the Flow.
I finally got it to run without any problems but there's still a problem when the screen opens. It won't let me write to it.....What should I do now????

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct Date
{
int month;
int day;
int year;
};
struct Car
{
double price;
Date purchased;
string customer;
};
void GetCar (ifstream& dataIn, Car& car)
{
dataIn >> car.customer;
dataIn >> car.price >> car.purchased.day
>> car.purchased.month >> car.purchased.year;
dataIn.ignore (2, '\n');
}
void WriteCar (ofstream& dataOut, Car car)
{
dataOut << "Customer; " << car.customer << endl
<< "Price: " << car.price << endl
<< "Purchashed: " << car.purchased.day << "/"
<< car.purchased.month << "/"
<< car.purchased.year << endl;
}

int main ()
{
Car car;
ifstream dataIn;
ofstream dataOut;
dataIn.open ("cars.dat");
dataOut.open ("cars.out");
cout << fixed << showpoint;

GetCar (dataIn,car);
while (dataIn)
{
car.price = car.price * 1.10;
WriteCar (dataOut, car);
GetCar (dataIn, car);
}
return 0;
}
Your program is written to read from a file, "cars.dat", and write to a file, "cars.out". I don't understand your question about allowing you to write to "it". I'm able to copy your source, compile, and run it successfully. Of course, I had to produce a cars.dat but that was pretty straight forward. BTW, in WriteCar, Purchashed should be Purchased.
Topic archived. No new replies allowed.