I can't find my mistake

Run code, you saw the error. Where did I make mistake ?

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
  #include<iostream>
#include<string>
using namespace std;

struct now
{
  int day1;
  int month1;
  int year1;
};

struct date
{
  int day;
  int month;
  int year;
};


struct Products
{
  string productName;
  double salary;
  date date1;
  now now1;
};

int
main ()
{
  Products products;
  int expire;
  int outOfDate = 0;

  int i = 0;
  int productCount;
  cout << "Please enter the Product Count: ";
  cin >> productCount;
  string ProductList[productCount][2];
  do
    {
      cout << "Please enter the Product Name: ";
      cin >> products.productName;
      cout << "Please enter the salary: ";
      cin >> products.salary;
      cout << "Please enter the create date DD.MM.YY : ";
      cin >> products.date1.day;
      cin >> products.date1.month;
      cin >> products.date1.year;
      cout << "Please enter the date of end DD.MM.YY: ";
      cin >> products.now1.day1;
      cin >> products.now1.month1;
      cin >> products.now1.year1;
      
      
      if ((products.now1.month1 * 30 + products.now1.day1) -
  (products.date1.month * 30 + products.date1.day) < 20)
{
  ProductList[i][0] = products.productName;
  ProductList[i][1] = products.salary;
}
      else
{
  outOfDate = outOfDate + 1;
  
}

      i++;
    }
  while (i < productCount);
  // string listOfData[];
  cout  << " out of date  product count: " << outOfDate<< endl;
  for(int j=0; j<productCount;j++)
  {
      cout<<"Product Name: "<<ProductList[j][0]<< endl;
  }
  return 0;
}
 
 string ProductList[productCount][2];


This is an array with a run-time defined size for one dimension. This isn't standard c++. If you need something like this, then use a vector. Consider:

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
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct now
{
	int day1;
	int month1;
	int year1;
};

struct date
{
	int day;
	int month;
	int year;
};

struct Products
{
	string productName;
	double salary;
	date date1;
	now now1;
};

int main()
{
	Products products;
	int outOfDate {};
	int productCount {};

	cout << "Please enter the Product Count: ";
	cin >> productCount;

	vector<Products> ProductList;

	for (int i = 0; i < productCount; ++i) {
		cout << "Please enter the Product Name: ";
		cin >> products.productName;

		cout << "Please enter the salary: ";
		cin >> products.salary;

		cout << "Please enter the create date DD MM YY : ";
		cin >> products.date1.day >> products.date1.month >> products.date1.year;

		cout << "Please enter the date of end DD MM YY: ";
		cin >> products.now1.day1 >> products.now1.month1 >> products.now1.year1;

		if ((products.now1.month1 * 30 + products.now1.day1) -
				(products.date1.month * 30 + products.date1.day) < 20)
			ProductList.push_back(products);
		else
			++outOfDate;
	}

	cout << "Out of date product count: " << outOfDate << '\n';

	for (int j = 0; j < ProductList.size(); ++j)
		cout << "Product Name: " << ProductList[j].productName << '\n';
}



Topic archived. No new replies allowed.