final project!

I'm trying to create a program that is for a car rental agency, its purpose is to find out what car is the most popular and the average number of days it was rented for. I've written the following but I'm not sure if it's even close to being right or good. Any help would be appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

/* This application will ask the user how many days have elapsed this year. Then it will ask the user for a vehicle type and how many days of that year they used it. The program will continue to do this until the user manually types control + z.                                            
*/


const int SIZE = 2;

int main()
{
	ofstream fileout("vehicle.dat");
	if (!fileout.is_open())
	{
		cout << "Error opening vehicle.dat, consult technical support." << endl;
		system("pause");
		exit(13);
	}

	
	int days_elapsed;
	int length = 0;
	int counter = 0;
	double average;
	double total = 0;

	
	string car_type[SIZE];
	int days_used[SIZE];
	double percent_utilization[SIZE];

	fileout << fixed << setprecision(1);
	cout << fixed << setprecision(1);


	fileout << left << setw(20) << "Car Type" << right
		<< setw(15) << "YTD Days Used"
		<< setw(25) << "Percent Utilization"
		<< '\n';

	cout << "How many days have elapsed this year? (1-365): ";
	cin >> days_elapsed;

	while (cin.fail() || days_elapsed<1 || days_elapsed>365)
	{
		cin.clear();
		cin.ignore(80, '\n');
		cout << "Error, re-enter days that have elapsed this year (1-365): ";
		cin >> days_elapsed;
	}

	for (; length<SIZE; length++)
	{
		cout << "Car Type (control+z to exit): ";
		cin >> car_type[length];

		if (cin.eof())
			break;

		cout << "How many days was the vehicle used?: ";
		cin >> days_used[length];

		while (cin.fail() || days_used[length]<1 || days_used[length]>days_elapsed)
		{
			cin.clear();
			cin.ignore(80, '\n');
			cout << "Error, re-enter how many days vehicle was used: ";
			cin >> days_used[length];
		}
	}

	
	if (length == SIZE)
		cout << "Array is full!" << endl;

	for (; counter<length; counter++)
	{
		percent_utilization[counter] = 100.*static_cast<double>(days_used[counter]) / days_elapsed;
		total += percent_utilization[counter];
	}

	
	if (length != 0)
		average = total / length;

	
	for (counter = 0; counter<length; counter++)
	{
		fileout << '\n' << left << setw(20) << car_type[counter]
			<< right << setw(15) << days_used[counter]
			<< setw(25) << percent_utilization[counter];

		if (percent_utilization[counter]<average)
			fileout << setw(22) << "*** Below Average ***";
	}

	fileout << "\n\n" << left << setw(15) << "Average" << right << setw(45) << average;

	system("type vehicle.dat");
	return 0;
I recommend these changes:
leave your name on it, make the amount of cars settable, and at the begining instead of using ofstream fileout("vehicle.dat"); you should use ofstream fileout; fileout.open("vehicle.dat");

EX:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <iomanip>
#include <fstream>
#include <windows.h>
using namespace std;

/* This application will ask the user how many days have elapsed this year.
Then it will ask the user for a vehicle type and how many days of that year they used it.
The program will continue to do this until the user manually types control + z.
*/
int main()
{
    int SiZe = 4;
	ofstream fileout; fileout.open("vehicle.dat");
	if (!fileout.is_open())
	{
		cout << "Error opening vehicle.dat, consult technical support." << endl;
		system("pause");
		return 13;
	}


	int days_elapsed;
	int length = 0;
	int counter = 0;
	double average;
	double total = 0;


	string car_type[SiZe];
	int days_used[SiZe];
	double percent_utilization[SiZe];

	fileout << fixed << setprecision(1);
	cout << fixed << setprecision(1);


	fileout << left << setw(20) << "Car Type" << right
		<< setw(15) << "YTD Days Used"
		<< setw(25) << "Percent Utilization"
		<< '\n';
cout<<"swisscheese23's Car Popularity Counter\n"<<endl;
    cout<<"How many cars are there?\n> ";
    cin>>SiZe;
	cout << "How many days have elapsed since last year? (1-365): ";
	cin >> days_elapsed;

	while (days_elapsed<1 || days_elapsed>365){
		cin.clear();
		cin.ignore(80, '\n');
		cout << "Error, re-enter days that have elapsed this year (1-365): ";
		cin >> days_elapsed;}
	for (; length<SiZe; length++){
		cout << "Car Type (control+z to exit): ";
		cin >> car_type[length];

		if (cin.eof())
			break;

		cout << "How many days was the vehicle used?: ";
		cin >> days_used[length];

		while (days_used[length]<1 || days_used[length]>days_elapsed)
		{
			cin.clear();
			cin.ignore(80, '\n');
			cout << "Error, re-enter how many days vehicle was used: ";
			cin >> days_used[length];}}

	if (length == SiZe)
    cout << "Array is full!" << endl;

	for (; counter<length; counter++)
	{
		percent_utilization[counter] = 100.*static_cast<double>(days_used[counter]) / days_elapsed;
		total += percent_utilization[counter];
	}


	if (length != 0)
		average = total / length;


	for (counter = 0; counter<length; counter++)
	{
		fileout << '\n' << left << setw(20) << car_type[counter]
			<< right << setw(15) << days_used[counter]
			<< setw(25) << percent_utilization[counter];

		if (percent_utilization[counter]<average)
			fileout << setw(22) << "*** Below Average ***";
	}

	fileout << "\n\n" << left << setw(15) << "Average" << right << setw(45) << average;

	system("type vehicle.dat");
	return 0;}
Topic archived. No new replies allowed.