Here is my problem. I have the code I've written so far below. Can anyone help!? lol
A. Create a file containing the following data about cars.
Car Owner
Car No.
Miles Driven
Gallons Used
John Jones
55
250
20
Mary James
67
350
10
Amy Smith
99
100
8
Joe Johns
88
123
86
Trudy Mains
56
1000
80
Mary Ames
97
238
15
B. Write a C program that reads the data in the file created in part A and displays the owner's name, car number, miles driven, gallons used and the miles per gallon for each car. The output should additionally contain the total miles driven, total gallons used, and average miles per gallon for all the cars. These totals should be displayed at the end of the output report.
Divide the program into appropriate functions.
This is what I've come up with so far. I'm not sure if I'm doing this right at all but it's better to attempt it than do nothing. So here it goes... I keep gettin these run errors after it's compiled!
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Linking...
pgm10-4.obj : error LNK2005: _main already defined in Cpp1.obj
final.obj : error LNK2005: _main already defined in Cpp1.obj
Debug/Cpp1.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Cpp1.exe - 3 error(s), 0 warning(s)
Code:
//Doug Miller
//Final Program, writing information to a file
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
char line[81] = {0};
char carOwner[10] = {0};
int carNo[4] = {0};
int milesDriven[10] = {0};
int gallonsUsed[10] = {0};
FILE *inFile;
inFile = fopen("test.dat", "r");
if (inFile == NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while (fgets(line,81,inFile) != NULL)
{
sscanf(line, "%s %d %d %d", carOwner, carNo, milesDriven, gallonsUsed);
printf("\nName: %s\nCar No: %d\nMiles Drien %d\nGallons Used:%d\n", carOwner, carNo, milesDriven, gallonsUsed);
}
fclose(inFile);
printf("\nThe file has been successfully written.\n");
_getch();
return 0;
}