Need homework assistance

Can't figure this one out. Please go easy on me, im new to this. Keep getting error and don't know how to fix

Assume that you have the following definition of a struct:

struct partsType
{
String partName;
Int partNum;
double price;
int quantitiesInStock;
};

Declare an array, inventory, of 100 components of type partsType.

Now take above struct definition above and:

Write a C++ code to initialize each component of inventory as follows: part name to null string, partNum to -1, price to 0.0 and quantities in quantitiesInStock to 0.
Write a C++ code that uses a loop to output the data stored in inventory. Assume that the variable length indicates the number of elements in inventory.
Note suggest testing your solution and submit outcome.
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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct partsType     // Definition of struct

	string partName;
	int partNum;
	double price;
	int quantitiesInStock;

};
int main () 
{
	struct partsType inventory[100] = {};  // Declares array called inventory with 100 components of type partsType

	int length = 100;
for (int I = 0; I < 100; i++)

{
inventory[i].partName << “”;  // Initializes each component inventory
inventory[i].partNum << -1;
inventory[i].price << 0.0;
inventory[i].quantitiesinstock << 0;
}
for (int I = 0; I < length; i++)  // Loop outputs data stored with inventory
		// Variable length indicates the number of elements in inventory
{
	cout << fixed << showpoint << setprecision(1);
cout << inventory[i].partName << endl;
cout << inventory[i].partNum << endl;
cout << inventory[i].price << endl;
cout << inventory[i].quantitiesInStock << endl;
  }
  return 0;
}
Write a C++ code to initialize each component of inventory as follows: part name to null string, partNum to -1, price to 0.0 and quantities in quantitiesInStock to 0.

Why aren't you using a constructor to initialize those variables to their default values?

Keep getting error and don't know how to fix

What exactly is this error?

Topic archived. No new replies allowed.