-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_7.cpp
55 lines (48 loc) · 1.08 KB
/
5_7.cpp
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
#include <iostream>
#include <string>
using namespace std;
struct Car
{
string manufacture;
int year;
};
int main()
{
int number = 0;
cout << "How many cars do you wish to catalog? ";
while(!(cin >> number) || 0 > number)
{
cout << "Error! Please enter a positive number: ";
cin.clear();
cin.sync();
}
cin.get();
Car * carCatalog = new Car[number];
for(int i = 0; i < number; i++)
{
cout << "Car #" << i + 1 << ":" << endl;
cout << "Please enter the make: ";
while(!getline(cin, carCatalog[i].manufacture))
{
cout << "Error! Please enter a string: ";
cin.clear();
cin.sync();
}
cout << "Please enter the year made: ";
while(!(cin >> carCatalog[i].year) || 0 > carCatalog[i].year)
{
cout << "Error! Please enter a positive number: ";
cin.clear();
cin.sync();
}
cin.get();
}
cout << "Here is your collection: " << endl;
for(int j = 0; j < number; j++)
{
cout << carCatalog[j].year << " " << carCatalog[j].manufacture << endl;
}
delete [] carCatalog;
// system("pause");
return 0;
}